Class Solution
-
- All Implemented Interfaces:
public final class Solution1894 - Find the Student that Will Replace the Chalk\.
Medium
There are
nstudents in a class numbered from0ton - 1. The teacher will give each student a problem starting with the student number0, then the student number1, and so on until the teacher reaches the student numbern - 1. After that, the teacher will restart the process, starting with the student number0again.You are given a 0-indexed integer array
chalkand an integerk. There are initiallykpieces of chalk. When the student numberiis given a problem to solve, they will usechalk[i]pieces of chalk to solve that problem. However, if the current number of chalk pieces is strictly less thanchalk[i], then the student numberiwill be asked to replace the chalk.Return the index of the student that will replace the chalk.
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.
Constraints:
chalk.length == n<code>1 <= n <= 10<sup>5</sup></code>
<code>1 <= chalki<= 10<sup>5</sup></code>
<code>1 <= k <= 10<sup>9</sup></code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegerchalkReplacer(IntArray chalk, Integer k)-
-
Method Detail
-
chalkReplacer
final Integer chalkReplacer(IntArray chalk, Integer k)
-
-
-
-