diff --git a/GeeksForGeeks/March/08-3-24/GFG.java b/GeeksForGeeks/March/08-3-24/GFG.java new file mode 100644 index 0000000..766421f --- /dev/null +++ b/GeeksForGeeks/March/08-3-24/GFG.java @@ -0,0 +1,62 @@ +//{ 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(" "); + String a = input[0]; + + Solution ob = new Solution(); + if(ob.sameFreq(a)){ + System.out.println(1); + } + else{ + System.out.println(0); + } + } + } +} +// } Driver Code Ends + + +//User function Template for Java + +class Solution +{ + boolean sameFreq(String s) + { + // code here + int arr[]=new int[26]; + + for(int i=0;i1) + return false; + + else if(Math.abs(ans-i)==1 && ++c==2) + return false; + } + } + + return true; + } +} diff --git a/GeeksForGeeks/March/08-3-24/README.md b/GeeksForGeeks/March/08-3-24/README.md new file mode 100644 index 0000000..9567f26 --- /dev/null +++ b/GeeksForGeeks/March/08-3-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(n) +Space complexity - O(1) diff --git a/LeetCode/March/08-3-24/README.md b/LeetCode/March/08-3-24/README.md new file mode 100644 index 0000000..7384c4b --- /dev/null +++ b/LeetCode/March/08-3-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(n) +Space complexity - O(n) diff --git a/LeetCode/March/08-3-24/Solution.java b/LeetCode/March/08-3-24/Solution.java new file mode 100644 index 0000000..5e21fee --- /dev/null +++ b/LeetCode/March/08-3-24/Solution.java @@ -0,0 +1,20 @@ +class Solution +{ + public int maxFrequencyElements(int[] nums) + { + int kMax = 100; + int ans = 0; + int[] count = new int[kMax + 1]; + + for (int num : nums) + ++count[num]; + + int maxFreq = Arrays.stream(count).max().getAsInt(); + + for (int freq : count) + if (freq == maxFreq) + ans += maxFreq; + + return ans; + } +}