Google Onsite Interview Round-3

Anonymous User
1796
May 28, 2025
May 28, 2025

You're given n balls, where each ball is assigned a color from 0 to k-1. You need to distribute them into bags, each with a capacity of k.

The goal is to minimize the number of bags used, with the constraint that each bag must satisfy one of the following two conditions:

  • Same-color bag: All balls in the bag are of the same color (e.g., RRR).
  • All-different-color bag: All balls in the bag have distinct colors (e.g., RGB).

I wasn't able to come up with a solution during the interview. I'd appreciate any ideas or strategies on how to approach this problem.

Comments (11)