LeetCode Problem 229
Link of the Problem to try -: Link
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= nums.length <= 5 * 104-109 <= nums[i] <= 109
Solution:
According to question says we have to create ArrayList in which we have to return those elements whose frequency count is more than array's length divided by 3 and we have to return it simply this is it.
And personally if I say this is a very easy question as there you don't need to think very much you can simply create a HashMap in which you maintain frequency of each element and then simply run a for each loop and iterate over the keys by keySet method of HashMap and then get value of each key and check is it greater than array.length/3 or not if it is then simply add in the ArrayList and here you got your ans.
Code:




