2037. Minimum Number of Moves to Seat Everyone | leetcode daily challenge | DSA | Hindi
ฝัง
- เผยแพร่เมื่อ 18 ก.ย. 2024
- Problem Name:
2037. Minimum Number of Moves to Seat Everyone
Problem Statement:
There are n seats and n students in a room. You are given an array seats of length n, where seats[i] is the position of the ith seat. You are also given the array students of length n, where students[j] is the position of the jth student.
You may perform the following move any number of times:
Increase or decrease the position of the ith student by 1 (i.e., moving the ith student from position x to x + 1 or x - 1)
Return the minimum number of moves required to move each student to a seat such that no two students are in the same seat.
Note that there may be multiple seats or students in the same position at the beginning.
Problem link:
leetcode.com/p...
Java Plus DSA Placement Course Playlist:
• Java and DSA Course Pl...
Java Plus DSA Sheet:
docs.google.co...
Notes:
github.com/Tiw...
Telegram Link:
shashwattiwari...
Ultimate Recursion Series Playlist:
• Recursion and Backtrac...
Instagram Handle: (@shashwat_tiwari_st)
shashwattiwari...
Samsung Interview Experience:
• I cracked Samsung | SR...
Company Tags:
Facebook | Amazon | Microsoft | Netflix | Google | LinkedIn | Pega Systems | VMware | Adobe | Samsung
Timestamp:
0:00 - Introduction
#ShashwatTiwari #coding #problemsolving
bhaiya you are one the best teacher bhaiya underrated matlab koi aise nahi alag alag approaches batata hai bhaiya
i did it like this understand the problem from you and tried to do it.
int minMovesToSeat(vector& seats, vector& students)
{
sort(seats.begin(),seats.end());
sort(students.begin(), students.end());
int diff = 0;
for(int i = 0; i< seats.size();i++)
{
diff += (abs(seats[i]-students[i]));
}
return diff;
}
time complexity = nlogn
Thanks 😊
good explaination
Bhaiya I was able to think of the brute force solution within 2 mins and coded it exactly as you did
Excellent work 👏
Vi a graph ar dp ki playlist chalu kor diji a joldi😊😊
sir which u explained before coding i get it but plz after code try to explain code too sometimes samj nhi aata ...
please provide the code also
sulemanbhasha dodmani
linkedin pe message kiya hu dekhe nhi ap