Handle Score
@Ibrahim Nash 6560
@blackshadows 6400
@mb1973 5777
@Quandray 5271
@akhayrutdinov 5111
@saiujwal13083 5074
@kirtidee18 4356
@sanjay05 3762
@mantu_singh 3638
@gfgaccount 3601
@marius_valentin_dragoi 3525
Complete Leaderboard
Check if frequencies can be equal
Easy Accuracy: 27.16% Submissions: 6222 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