Leetcode Problem 1894. Find the Student that Will Replace the Chalk

1894. Find the Student that Will Replace the Chalk

Leetcode Solutions

Using Prefix Sum and Modulo Operation

  1. Initialize a variable totalChalk to store the sum of all chalk requirements.
  2. Iterate through the chalk array to calculate totalChalk.
  3. Calculate the remaining chalk remainingChalk by taking the modulo of k with totalChalk.
  4. Iterate through the chalk array again and subtract each student's chalk requirement from remainingChalk.
  5. If at any point remainingChalk is less than the current student's requirement, return the index of that student.
  6. If all students can be satisfied with remainingChalk, return 0 as the process will start over.
UML Thumbnail

Iterative Simulation

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...