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; }
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
v easy explanation . thanks
Love from japan❤
Thanks 😊
Thank You
Question toh khud kar liya... Bas attendance lagane aaya hu😌
passing the parcel khelne wala samay jada behtaar tha 🥲🥲
💯
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;
}