Skip to content

Commit

Permalink
Added for 14 Jan
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed Jan 14, 2024
1 parent a57d32c commit bd4ad26
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
62 changes: 62 additions & 0 deletions GeeksForGeeks/14-1-24/GFG.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//{ Driver Code Starts
import java.util.*;
import java.io.*;

public class Main {

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int tc = Integer.parseInt(br.readLine().trim());
while (tc-- > 0) {
String[] inputLine;
inputLine = br.readLine().trim().split(" ");
int n = Integer.parseInt(inputLine[0]);
int m = Integer.parseInt(inputLine[1]);
int[][] arr = new int[n][m];

for(int i = 0; i < n; i++){
String[] s = br.readLine().trim().split(" ");
for(int j = 0; j < m; j++){
arr[i][j] = Integer.parseInt(s[j]);
}
}
ArrayList<Integer> ans = new Solution().repeatedRows(arr, n, m);
for(int i=0;i<ans.size();i++)
System.out.print(ans.get(i)+" ");

System.out.println();
}
}
}
// } Driver Code Ends


//User function Template for Java

class Solution
{
public static ArrayList<Integer> repeatedRows(int matrix[][], int m, int n)
{
//code here
TreeSet<Integer> set = new TreeSet<>();

ArrayList<Integer> ans = new ArrayList<>();

for(int i = 0; i < m; i++)
{
int num = 0;
for(int j = 0; j < n; j++)
{
num += matrix[i][j] << j;
}

if(set.contains(num))
ans.add(i);

else
set.add(num);
}

return ans;
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/14-1-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)
2 changes: 2 additions & 0 deletions LeetCode/14-1-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n)
Space complextiy - O(1)
28 changes: 28 additions & 0 deletions LeetCode/14-1-24/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Solution
{
public boolean closeStrings(String word1, String word2)
{
if (word1.length() != word2.length())
return false;

Map<Character, Integer> count1 = new HashMap<>();
Map<Character, Integer> count2 = new HashMap<>();

for (final char c : word1.toCharArray())
count1.merge(c, 1, Integer::sum);

for (final char c : word2.toCharArray())
count2.merge(c, 1, Integer::sum);

if (!count1.keySet().equals(count2.keySet()))
return false;

List<Integer> freqs1 = new ArrayList<>(count1.values());
List<Integer> freqs2 = new ArrayList<>(count2.values());

Collections.sort(freqs1);
Collections.sort(freqs2);

return freqs1.equals(freqs2);
}
}

0 comments on commit bd4ad26

Please sign in to comment.