Skip to content

Practice Find the Student that Will Replace the Chalk

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1894
LeetCode Problem

Find the Student that Will Replace the Chalk

Problem Statement

There are n students in a class numbered from 0 to n - 1. The teacher will give each student a problem starting with the student number 0, then the student number 1, and so on until the teacher reaches the student number n - 1. After that, the teacher will restart the process, starting with the student number 0 again. You are given a 0-indexed integer array chalk and an integer k. There are initially k pieces of chalk. When the student number i is given a problem to solve, they will use chalk[i] pieces of chalk to solve that problem. However, if the current number of chalk pieces is strictly less than chalk[i], then the student number i will be asked to replace the chalk. Return the index of the student that will replace the chalk pieces.

Source: Find the Student that Will Replace the Chalk on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
chalk = [5,1,5], k = 22
Output
0

# Example 2

Input
chalk = [3,4,1,2], k = 25
Output
1

Constraints

chalk.length == n
1 <= n <= 10^5
1 <= chalk[i] <= 10^5
1 <= k <= 10^9

Related LeetCode Problems

Practice more problems similar to Find the Student that Will Replace the Chalk.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.