Answer: ATLAN Hiring Challenge | Off-Campus OA (2025) | Using Strings and HashMap
Answer · Posted Jun 2026
Approach Count frequency of each character. Track: Maximum odd frequency. Minimum even frequency. Return: maxOdd - minEven Java Code import java.util.HashMap; import java.util.Map; class Solution { public int maxDifference(String s) { Map<Character, Integer> freq = new HashMap<>(); for (char c : s.toCharArray()) freq.merge(c, 1, Integer::sum); int maxOdd = Integer.MIN_VALUE; int minEven = Integer.MAX_VALUE; for (int f : freq.values()) { if (f % 2 == 1) maxOdd = Math.max(maxOdd, f); else minEven = Math.min(minEven, f); } return maxOdd - minEven; } ...
The full answer & interview discussion are available to premium members.
Log in Create a free account