diff --git a/GeeksForGeeks/March/11-3-24/GFG.java b/GeeksForGeeks/March/11-3-24/GFG.java new file mode 100644 index 0000000..f378580 --- /dev/null +++ b/GeeksForGeeks/March/11-3-24/GFG.java @@ -0,0 +1,89 @@ +//{ Driver Code Starts +//Initial Template for Java + +import java.io.*; +import java.util.*; + +class GFG { + public static void main(String args[]) throws IOException { + BufferedReader read = + new BufferedReader(new InputStreamReader(System.in)); + int t = Integer.parseInt(read.readLine()); + while (t-- > 0) { + String input[] = read.readLine().split(" "); + + int n = Integer.parseInt(input[0]); + int x = Integer.parseInt(input[1]); + + int mat1[][] = new int[n][n]; + + for(int i = 0;i= 0)) + { + int val = mat1[r1][c1] + mat2[r2][c2]; + + if (val == x) + { + count++; + c1++; + c2--; + } + + else if (val < x) + c1++; + + else + c2--; + + if (c1 == n) + { + c1 = 0; + r1++; + } + + if (c2 == -1) + { + c2 = n - 1; + r2--; + } + } + + return count; + } +} diff --git a/GeeksForGeeks/March/11-3-24/README.md b/GeeksForGeeks/March/11-3-24/README.md new file mode 100644 index 0000000..1d3ee04 --- /dev/null +++ b/GeeksForGeeks/March/11-3-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(n^2) +Space complexity - O(1) diff --git a/LeetCode/March/11-3-24/README.md b/LeetCode/March/11-3-24/README.md new file mode 100644 index 0000000..3a3350e --- /dev/null +++ b/LeetCode/March/11-3-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(|order| + |s|) +Space complexity - O(26) = O(1) diff --git a/LeetCode/March/11-3-24/Solution.java b/LeetCode/March/11-3-24/Solution.java new file mode 100644 index 0000000..365792a --- /dev/null +++ b/LeetCode/March/11-3-24/Solution.java @@ -0,0 +1,21 @@ +class Solution +{ + public String customSortString(String order, String s) + { + StringBuilder sb = new StringBuilder(); + int[] count = new int[128]; + + for (char c : s.toCharArray()) + ++count[c]; + + for (char c : order.toCharArray()) + while (count[c]-- > 0) + sb.append(c); + + for (char c = 'a'; c <= 'z'; ++c) + while (count[c]-- > 0) + sb.append(c); + + return sb.toString(); + } +}