Parallel String Counts with a Custom Hash Table
Updated
Problem statement
Count how many times each different string appears in words. Build your own hash table and make the counting safe to run in parallel.
Return one string key:count for each distinct key, ordered by the index of its first occurrence in the input. Counts include every occurrence across all worker chunks. The number of returned rows is the distinct-key count. Return an empty array for empty input.
Use at most workers actual threads or goroutines to process nonempty input; split the input into contiguous chunks. All workers must finish before results are returned. This practice version permits ordinary arrays, string operations, core thread/goroutine and synchronization primitives. It forbids built-in maps, sets, dictionaries, counters, and external hash-table or frequency-counting packages.
The table must resolve collisions, preserve exact counts under concurrency, and return the same output regardless of the order in which workers run. Discuss the synchronization and adjacent-memory tradeoffs when scaling the same approach to a million keys.
Function
countStrings(words: String[], workers: int) → String[]Examples
Example 1
words = ["pear","apple","pear","kiwi","apple"]workers = 3return = ["pear:2","apple:2","kiwi:1"]Counts aggregate across worker chunks. Output follows first input occurrences, not completion order.
Example 2
words = ["a","a","a","b","a","b"]workers = 8return = ["a:4","b:2"]At most one worker per input element is started; repeated keys from different workers merge into one row.
Example 3
words = []workers = 4return = []There are no keys to count and no output rows.
Constraints
0 <= words.length <= 5000.1 <= workers <= 8.- Each key has 1 to
32lowercase ASCII letters or decimal digits, so:is never part of a key. - Keys are case-sensitive. The input array is read-only during counting.
More NVIDIA Phone Screen questions
- Network Layer Execution OrderPHONE SCREEN · Seen Nov 2026
- Paged KV Cache AccessPHONE SCREEN · Seen Nov 2026
- Sliding Window Attention over a KV CachePHONE SCREEN · Seen Nov 2026
- Summarize Server Healthcheck LogsPHONE SCREEN · Seen Oct 2026
- Hash Partition OffsetsPHONE SCREEN · Seen Oct 2026
- Filter Paginated Medical RecordsPHONE SCREEN · Seen Oct 2026
- Least Frequently Used CachePHONE SCREEN · Seen Oct 2026
- Simulate a Reference-Counted Smart PointerPHONE SCREEN · Seen Aug 2026
- Streaming Top-K Frequent ElementsPHONE SCREEN · Seen Aug 2026
- Merge Multiple Sorted StreamsPHONE SCREEN · Seen Aug 2026
Similar questions at other companies
- Detect a Deadlock from Lock LogsHelm.ai · PHONE SCREEN
- Rank-Based Cache with a Data SourceLinkedIn · PHONE SCREENLinkedIn interview questions
- Bounded Service Instance RegistryRevolut · PHONE SCREENRevolut interview questions
- Concurrent Web Crawler SimulationOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Single-Flight Chunk CacheModal · PHONE SCREEN
- Thread-Safe Task Storage and Worker DispatchNuro · ONSITE INTERVIEWNuro interview questions
- Blocking Keyed Cache with Waiting ReadersDatabricks · ONSITE INTERVIEWDatabricks interview questions
- Cache an Expensive Service Across ThreadsOracle · ONSITE INTERVIEWOracle interview questions
- Blocking Connection Pool Operation TraceGoogle · ONSITE INTERVIEWGoogle interview questions
- Keyed Bounded Executor ScheduleMicrosoft · ONSITE INTERVIEWMicrosoft interview questions