Snowflake Interview Question: Determine Which Cake You Receive in a 1D Space Allocation Problem

22 Views
No Comments

Each person wants to eat one cake.

People tend to get the cake that is the closest to him/her.
However, if he/she finds that this cake already belongs to someone else, the person will give up that cake and look for the next closest cake.

The number of cakes is never smaller than the number of people, so everyone is guaranteed to get a cake.

Suppose you are one of the people in the space.
Given the array and your position, find out which cake belongs to you.

Example:
1 0 2 0 2 0 M 0M (me) will get the cake at index 4.

Each person chooses the closest cake. If the closest one is already taken, they move to the next closest. Since cakes ≥ people, everyone gets one. You are given your position and must determine which cake you will eventually receive based on conflict resolution rules.

The VOprep team has long accompanied candidates through various major company OAs and VOs, including SnowFlake, Google, Amazon, Citadel, SIG, providing real-time voice assistance, remote practice, and interview pacing reminders to help you stay smooth during critical moments. If you are preparing for these companies, you can check out our customized support plans—from coding interviews to system design, we offer full guidance to help you succeed.

END
 0