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​

Комментарии • 11

  • @shashwat_tiwari_st
    @shashwat_tiwari_st  Месяц назад +7

    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!!

  • @user-cr8pd4gn9t
    @user-cr8pd4gn9t Месяц назад

    Clear Explanation...thanks bro...!!

  • @saisree04
    @saisree04 Месяц назад

    Amazing explanation thank youuuu

  • @GirjeshSharma-zv3xo
    @GirjeshSharma-zv3xo Месяц назад +1

    Love from japan❤

  • @RohitKumar-dz8dh
    @RohitKumar-dz8dh Месяц назад +1

    Thanks 😊

  • @adarshjain3058
    @adarshjain3058 Месяц назад +1

    Question toh khud kar liya... Bas attendance lagane aaya hu😌

  • @eklavya22k34
    @eklavya22k34 Месяц назад

    v easy explanation . thanks

  • @PiyushSharma-we8yd
    @PiyushSharma-we8yd Месяц назад +2

    passing the parcel khelne wala samay jada behtaar tha 🥲🥲

  • @tanmoysenapati
    @tanmoysenapati Месяц назад

    Thank You

  • @ArunKumar-gx8iv
    @ArunKumar-gx8iv Месяц назад

    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;
    }