JavaScript String Duplicate Finder: Two Approaches Quiz
Tally character frequencies in a string two ways (explicit loop + counter dict and reduce one-liner), plus two companions on Unicode-aware iteration and duplicates-only filtering.
Question Bank
Hard
JavaScript
quiz
strings
hash-map
interview-prep
583 views
6
Implement findDuplicate(str) using an explicit for loop and a counter object. Return an object mapping every character to its occurrence count, INCLUDING characters that appear only once.
Examples
Example 1:
Input: "bcbaikcois"
Output: { b: 2, c: 2, a: 1, i: 2, k: 1, o: 1, s: 1 }
Explanation: Each character maps to how many times it appears in the input string.3 more questions, with full solutions and explanations, are available for premium members.
Upgrade to Premium