Reported September 2026
Googlehash table

Unique Elements in Range Queries

Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Google OA. Under 2s to a working solution.
Founder's read

Google's September 2026 report is a range-query problem where 200000 elements and 200000 queries make the obvious approach die instantly. Checking each range with a set is O(n) per query, so you're looking at 4 x 10^10 operations. The statement even tells you the target: O(1) per query after preprocessing. This is a hash-table plus prefix idea in disguise, and once you see it, it's about ten lines. If you blank during the live OA, StealthCoder runs invisibly on your desktop and surfaces the solution so you can recover instead of freezing.

The problem

For every inclusive query [left, right], determine whether all values in nums[left..right] are unique.
Return one boolean per query. Preprocess the array so each query is answered in O(1) time.

Function
uniqueRangeQueries(nums: int[], queries: int[][]) → boolean[]

Examples
Example 1
nums = [1,2,3,1]
queries = [[0,2],[1,3],[0,3],[2,2]]
return = [true,true,false,true]
Only the full range contains both occurrences of 1.
Example 2
nums = [5,5,5]
queries = [[0,0],[0,1],[1,2]]
return = [true,false,false]
Single-element ranges are unique; every longer range repeats 5.
Example 3
nums = [4,3,2,1]
queries = [[0,3],[1,2]]
return = [true,true]
The array contains no duplicate values.

Constraints
1 <= nums.length <= 200000.
-10^9 <= nums[i] <= 10^9.
1 <= queries.length <= 200000.
Every query has two indices satisfying 0 <= left <= right < nums.length.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: for each index i, compute the nearest earlier index prev[i] holding the same value, using a hash map of last-seen positions. Then build reach[r] = the max of prev[j] for all j <= r. A range [l, r] is unique exactly when reach[r] < l, meaning no element up to r has a duplicate that starts inside the range. Each query becomes a single comparison. Preprocessing is O(n) and queries are O(1). The common pitfall is using prev[r] alone, which only checks the last element and misses duplicates between earlier pairs inside the range. Another is initializing prev to 0 instead of -1, which breaks queries starting at index 0. Run Example 1 by hand: prev = [-1,-1,-1,0], reach = [-1,-1,-1,0]. Query [1,3] gives 0 < 1, true. Query [0,3] gives 0 < 0, false. If the logic slips live, StealthCoder is your hedge.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Unique Elements in Range Queries cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Google's OA.

Google reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Unique Elements in Range Queries FAQ

What's the trick to answering each query in O(1)?+

Track the previous index of the same value for every position, then keep a running maximum of those previous indices. A range [l, r] is all unique when that running maximum at r is less than l. One array lookup and one comparison per query.

Why doesn't checking only prev[r] work?+

A duplicate pair can sit entirely inside the range without involving the last element. For nums = [5,5,1] and range [0,2], prev[2] is -1 but the two 5s repeat. You need the prefix maximum of prev across all positions up to r.

How hard is this problem really?+

Medium. The code is short, but you have to spot that duplicates reduce to a single threshold per right endpoint. Once you see the prefix maximum idea, it's quick. Most people lose time trying segment trees or Mo's algorithm, which are overkill here.

What are the edge cases to test?+

Single-element queries like [2,2] must return true. Arrays with all equal values, like [5,5,5], should be false for any longer range. Initialize the prev sentinel to -1, not 0, so index 0 queries work. Values go up to 10^9 in magnitude, so use a hash map, not an array.

How do I prepare for this in 48 hours?+

Write the prev-index plus prefix-max solution from scratch twice, and trace Example 1 by hand. Then do a similar problem such as longest substring without repeating characters, which uses the same last-seen map idea. Focus on the pattern, not memorizing code.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Google.

OA at Google?
Invisible during screen share
Get it