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.

&nbsp;
Example 1:

Input: chalk = [5,1,5], k = 22
Output: 0
Explanation: The students go in turns as follows:
- Student number 0 uses 5 chalk, so k = 17.
- Student number 1 uses 1 chalk, so k = 16.
- Student number 2 uses 5 chalk, so k = 11.
- Student number 0 uses 5 chalk, so k = 6.
- Student number 1 uses 1 chalk, so k = 5.
- Student number 2 uses 5 chalk, so k = 0.
Student number 0 does not have enough chalk, so they will have to replace it.

Example 2:

Input: chalk = [3,4,1,2], k = 25
Output: 1
Explanation: The students go in turns as follows:
- Student number 0 uses 3 chalk so k = 22.
- Student number 1 uses 4 chalk so k = 18.
- Student number 2 uses 1 chalk so k = 17.
- Student number 3 uses 2 chalk so k = 15.
- Student number 0 uses 3 chalk so k = 12.
- Student number 1 uses 4 chalk so k = 8.
- Student number 2 uses 1 chalk so k = 7.
- Student number 3 uses 2 chalk so k = 5.
- Student number 0 uses 3 chalk so k = 2.
Student number 1 does not have enough chalk, so they will have to replace it.


&nbsp;
Constraints:


	chalk.length == n
	1 &lt;= n &lt;= 105
	1 &lt;= chalk[i] &lt;= 105
	1 &lt;= k &lt;= 109


class Solution:
    def chalkReplacer(self, chalk: List[int], k: int) -> int:
        x = sum(chalk)
        if x<k:
            k = k%x
        if x == k:
            return 0
        i = 0
        n = len(chalk)
        while True:
            if chalk[i]<=k:
                k -= chalk[i]
            else:
                break
            i +=1
               
        return i
class Solution {

public int chalkReplacer(int[] chalk, int k) {
    long sum = 0;
    for (int c : chalk) {
        sum += c;
    }
    long left = k % sum; 
    for (int i = 0; i < chalk.length; i++){
        if(left >= chalk[i]){ 
            left -= chalk[i];
        } else {    
            return i;
        }
    }
    return -1;  //just for return statement, put whatever you want here
}
}
class Solution {
public:
    // T(n) = O(n) S(n) = O(1) 
    int chalkReplacer(vector<int>& chalk, int k) {
        // Size of the vector
        int n = chalk.size();
        // Store the sum of the elements in the vector
        long sum = 0;
        // Calculate the sum of the elements 
        for (int n : chalk) sum += n;
        // Update k as the remainder of the sum 
        // to make sure that the while loop
		// will traverse the vector at most 1 time
        k = k % sum;
        // Start from the initial value in the array
        int idx = 0;
        // While the next student has enough chalk
        while (k >= chalk[idx]) {
            // Decrease the remaining chalk
            k -= chalk[idx];
            // Increase the index
            idx = (idx + 1) % n;
        }
        // Return the index of the student without
        // enough chalk
        return idx;
    }
};
var chalkReplacer = function(chalk, k) {
    const sum = chalk.reduce((r, c) => r + c, 0);
    
    k %= sum;
    
    for (let i = 0; i < chalk.length; i++) {
        if (chalk[i] > k) {
            return i;
        }

        k -= chalk[i];
    }
};
Find the Student that Will Replace the Chalk