diff --git a/GeeksForGeeks/March/28-3-24/GFG.java b/GeeksForGeeks/March/28-3-24/GFG.java new file mode 100644 index 0000000..c907327 --- /dev/null +++ b/GeeksForGeeks/March/28-3-24/GFG.java @@ -0,0 +1,84 @@ +//{ Driver Code Starts +// Initial Template for Java + +import java.util.*; +import java.io.*; +import java.lang.*; + +class Main { + public static void main(String[] args) throws IOException { + Scanner sc = new Scanner(System.in); + int t = sc.nextInt(); + + while (t-- > 0) { + + int n = sc.nextInt(); + int m = sc.nextInt(); + int[][] adj = new int[m][3]; + + for (int i = 0; i < m; i++) { + + for (int j = 0; j < 3; j++) { + adj[i][j] = sc.nextInt(); + } + } + + int dist = sc.nextInt(); + Solution obj = new Solution(); + int ans = obj.findCity(n, m, adj, dist); + System.out.println(ans); + } + } +} + +// } Driver Code Ends + + +// User function Template for Java + +class Solution { + int findCity(int n, int m, int[][] edges,int distanceThreshold) + { + //code here + int min=101; + int ans=-1; + int[][] mat=new int[n][n]; + + for(int[] mm: mat) + Arrays.fill(mm,10001); + + for(int i=0;i count = new HashMap<>(); + + for (int l = 0, r = 0; r < nums.length; ++r) + { + count.merge(nums[r], 1, Integer::sum); + + while (count.get(nums[r]) == k + 1) + count.merge(nums[l++], -1, Integer::sum); + + ans = Math.max(ans, r - l + 1); + } + + return ans; + } +}