Flipkart SDE-1

flipkart logo
flipkart
SDE-1
October 2, 20254 reads

Summary

I encountered a challenging problem during my Flipkart SDE-1 interview that involved maximizing the number of filled baskets given N balls of various colors and a requirement of K different colors per basket.

Full Experience

During my Flipkart SDE-1 interview, I was presented with a complex algorithmic problem. The core task was to determine the maximum number of baskets that could be filled. A basket was considered filled if it contained at least K balls of different colors, and I had N balls, with their colors provided in an array. I recognized this as a problem suitable for a binary search approach on the answer. My strategy involved setting left = 0 and right = N / K and then checking if a mid number of baskets was achievable. The check involved iterating through the frequency map of colors; for each color, I could use at most mid balls across all mid baskets. If the total balls used (balls += min(mid, it.second)) met the condition (balls >= (k * mid)), I knew mid was possible and tried for more; otherwise, I reduced my search space.

Interview Questions (1)

Q1
Maximize Filled Baskets with K Different Colors
Data Structures & AlgorithmsHard

You are given N balls and an integer K. The color of each ball is given in an array. A basket is filled if it contains at least K balls of different colors. Find the maximum number of filled baskets you can get if you optimally put the balls in the baskets.

Discussion (0)

Share your thoughts and ask questions

Join the Discussion

Sign in with Google to share your thoughts and ask questions

No comments yet

Be the first to share your thoughts and start the discussion!