Handle Score
@Ibrahim Nash 5725
@blackshadows 5685
@akhayrutdinov 5111
@mb1973 4989
@Quandray 4908
@saiujwal13083 4156
@sanjay05 3762
@marius_valentin_dragoi 3511
@sushant_a 3453
@KshamaGupta 3318
@the_coder95 3302
Complete Leaderboard
Check if frequencies can be equal
Easy Accuracy: 13.74% Submissions: 1154 Points: 2

Given a string s which contains only lower alphabetic characters, check if it is possible to remove at most one character from this string in such a way that frequency of each distinct character becomes same in the string.

Example 1:

s = xyyz
Output: 1 
Explanation: Removing one 'y' will make 
frequency of each letter 1.

Example 2:

s = xxxxyyzz
Output: 0
Explanation: Frequency can not be made same 
same by removing just 1 character.

Your Task:  
You dont need to read input or print anything. Complete the function sameFreq() which takes a string as input parameter and returns a boolean value denoting if same frequency is possible or not.
Note: The driver code print 1 if the value returned is true, otherwise 0.

Expected Time Complexity: O(N) where N is length of str
Expected Auxiliary Space: O(1)

1 <= str.length() <= 104


to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Check if frequencies can be equal

Output Window