Find the Student that Will Replace the Chalk | 2 Ways | Leetcode 1894 | codestorywithMIK
Whatsapp Community Link : https://www.whatsapp.com/channel/0029...
This is the 105th Video of our Playlist "Array 1D/2D : Popular Interview Problems" by codestorywithMIK
In this video we will try to solve a simple Simulation Array Problem : Find the Student that Will Replace the Chalk | 2 Ways | Leetcode 1894 | codestorywithMIK
I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.
Problem Name : Find the Student that Will Replace the Chalk | 2 Ways | Leetcode 1894 | codestorywithMIK
Company Tags : will update soon
My solutions on Github(C++ & JAVA) - https://github.com/MAZHARMIK/Intervie...
Leetcode Link : https://leetcode.com/problems/find-th...
My Personal Blog & Behind The Scenes - / @weekendwithmik
My DP Concepts Playlist : • Roadmap for DP | How to Start DP ? | ...
My Graph Concepts Playlist : • Graph Concepts & Qns - 1 : Graph will...
My Recursion Concepts Playlist : • Introduction | Recursion Concepts And...
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Intervie...
Instagram : / codestorywithmik
Facebook : / 100090524295846
Twitter : / cswithmik
Subscribe to my channel : / @codestorywithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
Summary :
Approach 1: Simulation (TLE)
Description: This approach simulates the chalk usage by iterating through the students in a loop and subtracting their chalk requirements from k until k becomes less than a student's chalk requirement. The simulation continues until the condition is met.
Time Complexity: O(k/sum * n) — where sum is the total sum of chalk requirements in one full iteration and n is the number of students. This can result in a Time Limit Exceeded (TLE) error for large inputs, as k might be very large.
Space Complexity: O(1) — The approach only uses a constant amount of extra space.
Approach 2: Remainder Optimization
Description: Instead of simulating the entire process, this approach calculates the total chalk required for one complete round of all students (totalChalkSum). It then computes the remainder of k when divided by totalChalkSum (remainChalk). This allows us to reduce the problem to a smaller equivalent by only considering the remaining chalk. Finally, it finds the first student whose chalk requirement exceeds remainChalk.
Time Complexity: O(n) — The total chalk sum is computed in one pass, and finding the student who runs out of chalk takes another pass.
Space Complexity: O(1) — This approach also only uses a constant amount of extra space.
✨ Timelines✨
00:00 - Introduction
0:17 - Problem Explanation
2:52 - Simulation Approach - TLE
6:52 - Improved Approach - Accepted
13:20 - Coding it up
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #coding #programming #100daysofcode #developers #techjobs #datastructures #algorithms #webdevelopment #softwareengineering #computerscience #pythoncoding #codinglife #coderlife #javascript #datascience #leetcode #leetcodesolutions #leetcodedailychallenge #codinginterview #interviewprep #technicalinterview #interviewtips #interviewquestions #codingchallenges #interviewready #dsa #hindi #india #hindicoding #hindiprogramming #hindiexplanation #hindidevelopers #hinditech #hindilearning #helpajobseeker #jobseekers #jobsearchtips #careergoals #careerdevelopment #jobhunt #jobinterview #github #designthinking #learningtogether #growthmindset #digitalcontent #techcontent #socialmediagrowth #contentcreation #instagramreels #videomarketing #codestorywithmik #codestorywithmick #codestorywithmikc #codestorywitmik #codestorywthmik #codstorywithmik #codestorywihmik #codestorywithmiik #codeistorywithmik #codestorywithmk #codestorywitmick #codestorymik #codestorwithmik