Most Frequent String in an Array

viaLeetCode

Problem: Given an array of strings, find the string with the highest frequency of occurrence.

Constraints: Array can contain duplicate strings.

Example: ["hello", "world", "world", "bar", "hello", "hello"] -> "hello" (frequency = 3).

Approach: Use a hashmap to count occurrences of each string in a single pass, then scan the map to find the entry with maximum count. O(n) time, O(n) space.

Add a follow-up question they asked
No follow-ups yet. Be the first to add one.
asked …
LeaderboardSalary
Language
Account