Snowflake interview question
Minimum distance between any person and any cake in an array
- Company:
- Snowflake
- Type:
- Coding
- Difficulty:
- Easy
- Reported:
- November 10, 2026
Problem
You are given a 1D array A of length n where each element is 0, 1 or 2:
0means the position is empty,1means a person stands there,2means a cake is there.
Compute the minimum distance (difference of indices) between any person and any cake.
Example 1
Input: A = [1, 0, 0, 2, 0, 1]
Output: 2
The cake at index 3 is 3 away from the person at 0 and 2 away from the person at 5.
Example 2
Input: A = [2, 0, 1, 1, 0, 0, 2]
Output: 2
The person at index 2 is 2 away from the cake at index 0.
Constraints
- Each element is in {0, 1, 2}.
- Other limits not stated; ask the interviewer.
Reported by candidates or drawn from publicly available sources, and rewritten in our own words. Pathwise Prep does not publish confidential assessment content. Report a concern