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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

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
Backtracking
Permutations with duplicates
Pruning
Counting
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported