Answer: FLIXSTOCK Hiring Challenge | Campus Online Assessment Question | On-Campus (2023
Answer · Posted Jun 2026
Approach Count the frequency of each character. Store all frequencies in a set. If all frequencies are identical, the set size will be 1. Otherwise, return false. Strategy Use a HashMap to count frequencies. Use a HashSet to store frequency values. Equal frequencies produce only one unique value. Java Code import java.util.*; class Solution { public boolean areOccurrencesEqual(String s) { Map<Character, Integer> freq = new HashMap<>(); for (char c : s.toCharArray()) { freq.merge(c, 1, Integer::sum); } return new HashSet<>(freq.values()).size() == ...
The full answer & interview discussion are available to premium members.
Log in Create a free account