The Find the Student that Will Replace the Chalk interview question is a cyclic simulation problem. students sit in a circle, and each student needs chalk[i] pieces of chalk to solve a problem. You start with a total amount of k chalk. The teacher gives chalk to student 0, then 1, and so on, wrapping back to 0 after student . You need to find the index of the student who will run out of chalk (i.e., when ).
Companies like Google and Bloomberg ask the Find the Student that Will Replace the Chalk coding problem to test if a candidate can optimize a repeating process. While a simple simulation would take passes, the correct approach uses Prefix Sums and Modulo to solve it in or . It evaluations your ability to handle large numeric inputs ( up to ).
This problem follows the Modulo and Binary Search pattern.
total = sum(chalk).k_remaining = k % total.chalk[i] from k_remaining until it becomes negative.prefixSum[i] > k_remaining.Chalk needed: [3, 4, 1, 2], total .
long or BigInt).Always look for "periodicity" in simulation problems. If an array is traversed repeatedly, the sum of the array is the "period," and the modulo operator is the "shortcut" to the final cycle. This is a vital Prefix Sum interview pattern.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Zero Array Transformation II | Medium | Solve | |
| Find the Minimum Amount of Time to Brew Potions | Medium | Solve | |
| Special Array II | Medium | Solve | |
| Maximum Average Subarray II | Hard | Solve | |
| Ant on the Boundary | Easy | Solve |