1894. Find the Student that Will Replace the Chalk

  Рет қаралды 62

CodeVia

CodeVia

7 ай бұрын

1894. Find the Student that Will Replace the Chalk #leetcodequestionandanswers #java #coding #microsoftinterview #javainterviewquestions #interview #amazoninterviewpreparation #googleinterview #leetcode #javaprogramming
leetcode.com/problems/find-th...
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.
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.

Пікірлер: 1
@bsrayat8200
@bsrayat8200 7 ай бұрын
Well explained!
YCW Meets Rainn Wilson, Philanthropist, Author, and "Dwight Schrute" in "The Office".
31:10
Young Citizens of the World (YCW)
Рет қаралды 3,9 М.
Sigma girl and soap bubbles by Secret Vlog
00:37
Secret Vlog
Рет қаралды 13 МЛН
Alex hid in the closet #shorts
00:14
Mihdens
Рет қаралды 14 МЛН
Женская драка в Кызылорде
00:53
AIRAN
Рет қаралды 478 М.
Useful gadget for styling hair 🤩💖 #gadgets #hairstyle
00:20
FLIP FLOP Hacks
Рет қаралды 8 МЛН
Winning Facebook (Meta) Hacker Cup Qual Round 2022?
53:55
Neal Wu
Рет қаралды 2,3 МЛН
Greedy Algorithms Tutorial - Solve Coding Challenges
1:53:09
freeCodeCamp.org
Рет қаралды 313 М.
The moment we stopped understanding AI [AlexNet]
17:38
Welch Labs
Рет қаралды 797 М.
Nature's Incredible ROTATING MOTOR (It’s Electric!) - Smarter Every Day 300
29:37
Sigma girl and soap bubbles by Secret Vlog
00:37
Secret Vlog
Рет қаралды 13 МЛН