Distinct Arrangements of Repeated Thumbnails in a Collage Row
Last updated: November 29, 2026
Quick Overview
Google Photos lays out a single collage row from a list of thumbnail IDs where some IDs repeat. Return every distinct left-to-right arrangement of the row.
0
0
0 solved
Google Photos lays out a single collage row from a list of thumbnail IDs where some IDs repeat. Return every distinct left-to-right arrangement of the row.
A natural follow-up in Google screens after plain permutations. The interviewer checks that you prune duplicates during the search using sorting plus a precise skip condition, rather than generating n! orders and deduping.
What the Interviewer Expects
- Sorts the input and uses a used array
- Skips nums[i] when it equals nums[i-1] and nums[i-1] is not used
- Explains why that condition fixes a canonical order among equal items
- Relates the count to the multinomial n! / product of count_c!
- Offers a counter-based alternative
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Rewrite it using a Counter of remaining items instead of a used array.
- How would you count arrangements without listing them?
- How would you enforce that no two identical thumbnails sit next to each other?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: list of thumbnail IDs with possible repeats, for example
[7, 7, 9]. - Output: each distinct arrangement exactly once:
[7,7,9],[7,9,7],[9,7,7]. - Row length is small (at most about 8...
High-Level Design
I prefer the Counter formulation because the dedupe is automatic: at each position, iterate over distinct remaining IDs, place one, decrement its count, recurse, then restore. Since we branch on dis...