Number of Students Unable to Eat Lunch | 2 Approaches | Leetcode 1700 | codestorywithMIK
codestorywithMIK codestorywithMIK
69.4K subscribers
6,657 views
310

 Published On Apr 7, 2024

Whatsapp Community Link : https://www.whatsapp.com/channel/0029...
This is the 30thVideo of our Playlist "Leetcode Easy: Popular Interview Problems".

In this video we will try to solve an easy but a very good practice problem : Number of Students Unable to Eat Lunch | Leetcode 1700

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 : Number of Students Unable to Eat Lunch | 2 Approaches | Leetcode 1700 | codestorywithMIK
Company Tags : Amzon
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Intervie...
Leetcode Link : https://leetcode.com/problems/number-...


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  

Approach Summary :
Approach-1:
This approach simulates the process of serving sandwiches to students by using a queue to represent the line of students waiting to be served and a stack to represent the sandwiches available for serving. The algorithm iterates over both queues and stacks, attempting to serve sandwiches to students according to their preferences. If a sandwich matches a student's preference, both the sandwich and the student are removed from their respective queues. If not, the student moves to the back of the queue. This process continues until either all students are served or there are no more sandwiches available. The time complexity of this approach is O(n), where n is the number of students, and the space complexity is O(n) due to the storage of the queues and stacks.

Approach-2:
This approach utilizes a counter-based approach to track the number of students who prefer circular and square sandwiches. It iterates over both the students and the sandwiches, counting the occurrences of each preference. Then, it serves sandwiches to students based on their preferences, decrementing the count of available sandwiches accordingly. If there are no more sandwiches available for a particular preference, the algorithm returns the count of remaining unserved students. The time complexity of this approach is O(n), where n is the number of students, and the space complexity is O(1) since it uses only a constant amount of extra space for storing the preference counts.

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

✨ Timelines✨
00:00 - Introduction
5:22 - Approach-1 Simulation
09:40 - Approach-2 + Dry Runs
16:19 - 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 #newyear2024

show more

Share/Embed