Reported December 2024
Googledepth first search

Number of Distinct Islands

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 December 2024 OA included a distinct islands problem, and it's the kind of graph-traversal question that looks simple until you miscount. You're scanning a grid for isolated landmasses, but the trick isn't just counting connected components. It's identifying whether two islands that look different are actually the same shape rotated or reflected. If you blank on the shape-normalization trick during the live OA, StealthCoder will feed you the pattern in real time so you don't tank the submission.

Pattern and pitfall

The core pattern is depth-first search or breadth-first search to identify each island, but the hard part is distinguishing truly distinct islands from duplicates. Most candidates code the basic connectivity part fine, then realize they've over-counted because they didn't normalize island shapes. The standard solution involves converting each island's coordinates to a canonical form, usually by translating to the origin and storing the sorted set of cells. This eliminates rotation and reflection duplicates. Some versions require you to check all 8 rotations and reflections explicitly. StealthCoder acts as your live safety net if the normalization step doesn't click during the assessment.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Number of Distinct Islands 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. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as number of distinct islands. If you have time before the OA, drill that.

⏵ The honest play

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

Google reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Number of Distinct Islands FAQ

Does Google care about rotations and reflections as different islands?+

Yes, typically. Two islands with the same shape but different rotation count as one if you're solving the 'truly distinct' version. The problem text matters here. If it's vague, assume you need to normalize. That's where most candidates lose points.

Is this just a standard graph-traversal problem?+

It starts as one. DFS or BFS finds connected components. But the second half is the real test: shape comparison and deduplication. That's where the algorithmic meat is. Don't skip it.

How do I normalize island shapes quickly under time pressure?+

Translate all coordinates so the minimum row and column are zero, then sort the set of cells. Store as a tuple or string. Two islands with the same canonical form are duplicates. Simple, fast, no rotation logic needed.

What's the time complexity I should target?+

Grid traversal is O(rows * cols) for DFS/BFS. Normalizing each island is O(island_size * log(island_size)). Overall O(rows * cols) for most inputs. Don't overthink it. Just code it clean.

Will this problem appear again or is it stale?+

Graph and grid problems are evergreen at Google. This specific variant circulates. The shape-deduplication trick is commonly retested because most candidates either nail it or completely miss it. Know the pattern.

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