2582. Pass the Pillow | Maths | leetcode daily challenge | DSA | Hindi
HTML-код
- Опубликовано: 22 авг 2024
- Problem Name:
2582. Pass the Pillow
Problem Statement:
There are n people standing in a line labeled from 1 to n. The first person in the line is holding a pillow initially. Every second, the person holding the pillow passes it to the next person standing in the line. Once the pillow reaches the end of the line, the direction changes, and people continue passing the pillow in the opposite direction.
For example, once the pillow reaches the nth person they pass it to the n - 1th person, then to the n - 2th person and so on.
Given the two positive integers n and time, return the index of the person holding the pillow after time seconds.
Problem Link:
leetcode.com/p...
Graph Playlist:
• Graph Data Structure S...
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
like target is 80. Also, ye medium level problem hai okay, this is not easy one, agar optimised solution code na kr pae ho toh tension mat lena!!
Clear Explanation...thanks bro...!!
Amazing explanation thank youuuu
Love from japan❤
Thanks 😊
Question toh khud kar liya... Bas attendance lagane aaya hu😌
v easy explanation . thanks
passing the parcel khelne wala samay jada behtaar tha 🥲🥲
💯
Thank You
Brute Force solution with 100% faster
public int passThePillow(int n, int time) {
int pillowPosition = 1;
int currentTime = 0;
boolean isBack = false;
// time is taken modulo 2n-2 because the pillow completes a round in 2n-2 seconds
time = time * (2 * n - 2);
while (currentTime < time) {
if (!isBack) {
pillowPosition++;
} else {
pillowPosition--;
}
if (pillowPosition == 1 || pillowPosition == n) {
isBack = !isBack;
}
currentTime++;
}
return pillowPosition;
}