diff --git a/GeeksForGeeks/May/12-5-24/GFG.java b/GeeksForGeeks/May/12-5-24/GFG.java new file mode 100644 index 0000000..9c33d27 --- /dev/null +++ b/GeeksForGeeks/May/12-5-24/GFG.java @@ -0,0 +1,41 @@ +//{ Driver Code Starts +// Initial Template for Java + +import java.io.*; +import java.util.*; + +class GFG { + public static void main(String args[]) throws IOException { + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + int t = Integer.parseInt(in.readLine()); + while (t-- > 0) { + int d = Integer.parseInt(in.readLine()); + + Solution ob = new Solution(); + System.out.println(ob.minSteps(d)); + } + } +} +// } Driver Code Ends + + +// User function Template for Java + +class Solution +{ + static int minSteps(int d) + { + // code here + int res = steps(d, 0, 0); + return res; + } + + private static int steps(int d, int i, int j) + { + if(i-d >= 0 && (i-d)%2 == 0) + return j; + + j++; + return steps(d, i+j, j); + } +} diff --git a/GeeksForGeeks/May/12-5-24/README.md b/GeeksForGeeks/May/12-5-24/README.md new file mode 100644 index 0000000..9567f26 --- /dev/null +++ b/GeeksForGeeks/May/12-5-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(n) +Space complexity - O(1) diff --git a/LeetCode/May/12-5-24/README.md b/LeetCode/May/12-5-24/README.md new file mode 100644 index 0000000..d345d8d --- /dev/null +++ b/LeetCode/May/12-5-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(m*n) +Space complexity - O(m*n) diff --git a/LeetCode/May/12-5-24/Solution.java b/LeetCode/May/12-5-24/Solution.java new file mode 100644 index 0000000..8ac9e4e --- /dev/null +++ b/LeetCode/May/12-5-24/Solution.java @@ -0,0 +1,16 @@ +class Solution +{ + public int[][] largestLocal(int[][] grid) + { + int n = grid.length; + int[][] ans = new int[n - 2][n - 2]; + + for (int i = 0; i < n - 2; ++i) + for (int j = 0; j < n - 2; ++j) + for (int x = i; x < i + 3; ++x) + for (int y = j; y < j + 3; ++y) + ans[i][j] = Math.max(ans[i][j], grid[x][y]); + + return ans; + } +}