Imagine a classroom where students take turns solving problems in a circular fashion. There are n students numbered from 0 to n-1, and they sit in a circle. The teacher starts with student 0, then moves to student 1, and so on. After reaching student n-1, the teacher wraps around back to student 0.
Each student needs a certain amount of chalk pieces to solve their assigned problem. You're given an array chalk where chalk[i] represents how many pieces student i needs. Initially, there are k chalk pieces available.
Here's the catch: if when it's a student's turn, there aren't enough chalk pieces left for them to complete their problem, that student must go replace the chalk instead of solving the problem.
Goal: Determine which student will be the one asked to replace the chalk.
Example: If chalk = [5,1,5] and k = 11, student 0 uses 5 pieces (6 left), student 1 uses 1 piece (5 left), student 2 uses 5 pieces (0 left), then when we cycle back to student 0, there are 0 pieces left but they need 5, so student 0 replaces the chalk.
Input & Output
Constraints
- 1 โค chalk.length โค 105
- 1 โค chalk[i] โค 105
- 1 โค k โค 109
- All array elements are positive integers