Skip to content

Commit

Permalink
Added codes for 12 May
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed May 12, 2024
1 parent cdbbd4d commit 76ad07f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
41 changes: 41 additions & 0 deletions GeeksForGeeks/May/12-5-24/GFG.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/May/12-5-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n)
Space complexity - O(1)
2 changes: 2 additions & 0 deletions LeetCode/May/12-5-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(m*n)
Space complexity - O(m*n)
16 changes: 16 additions & 0 deletions LeetCode/May/12-5-24/Solution.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 76ad07f

Please sign in to comment.