2940. Find Building Where Alice and Bob Can Meet | Monotonic stack | Priority Queue

Поделиться
HTML-код
  • Опубликовано: 23 дек 2024

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

  • @ARYANMITTAL
    @ARYANMITTAL  День назад +6

    What did Infosys Smoke 🚬 - ruclips.net/user/shortsISgd5Ymdjxs?feature=share

    • @rajrajesh1669
      @rajrajesh1669 День назад

      Infosys dev expectation : 🗿
      Infosys dev package: 🤡

  • @ayaaniqbal3531
    @ayaaniqbal3531 22 часа назад +1

    Aryan Bhai try to do a full dry run of the your code so that the explanation is crystal clear.

  • @satguy8481
    @satguy8481 День назад +2

    bhai ne itna ghumaya ki mera dimag ghum gya

  • @chinmay3587
    @chinmay3587 День назад +1

    The intuition is on point , great explanation!!!
    keep it up and thank you!

  • @ceciljoel9577
    @ceciljoel9577 12 часов назад +1

    How much time it took you to solve this problem?

  • @LinhHoang-ml1qo
    @LinhHoang-ml1qo День назад

    Thank you teacher, your great explaination helped me a lots

  • @Up78riderkanpur
    @Up78riderkanpur День назад +2

    dont use double line reflecting pens..

  • @study-yd6es
    @study-yd6es День назад +2

    Keep posting these amazing lectures Aryan

  • @The.Vikings
    @The.Vikings День назад

    In the binary search when we find no>height we should go to the left side as in left there can be height which is less than no greater than height and have low index ??

  • @akshayrajput6027
    @akshayrajput6027 День назад +3

    12:10 - 12:14 Did i hear that right ? (Hawas 😂)

  • @harshalyallewar
    @harshalyallewar 9 часов назад

    please dont increase speed of video implicitly in your editing itself

  • @SanjayKumar-iu7rq
    @SanjayKumar-iu7rq День назад

    You did not explain the binary search part of the code🙂

  • @modiashish1775
    @modiashish1775 День назад

    what is wrong in my code
    vector leftmostBuildingQueries(vector& heights, vector& queries)
    {
    int n = queries.size() ;
    vector ans( n , -1 ) ;
    for( int i = 0 ; i < n ; i++ )
    {
    int a = queries[i][0] ;
    int b = queries[i][1] ;
    for( int j = max(a,b) ; j < heights.size() ; j++ )
    {
    if( heights[a]

  • @nihalsingh6233
    @nihalsingh6233 День назад +2

    My Approach ----> 949 / 952 testcases passed
    class Solution {
    public:
    vector leftmostBuildingQueries(vector& heights, vector& queries) {
    int n = heights.size();
    // Step 1 : Find the NGE in right
    vectorrightMax(n, -1);
    stackst;
    for(int i = 0; i < n; i++){
    while(!st.empty() && heights[st.top()] < heights[i]){
    rightMax[st.top()] = i;
    st.pop();
    }
    st.push(i);
    }
    // Step 2 : Now compute your answer
    int m = queries.size();
    vectorans(m, -1);
    for(int k = 0; k < m; k++){
    int i = min(queries[k][0], queries[k][1]);
    int j = max(queries[k][0], queries[k][1]);
    // Check
    if(heights[i] < heights[j] || i == j){
    ans[k] = j;
    }else{
    int temp = j;
    while(temp < n && rightMax[temp] != -1 && heights[i] >= heights[rightMax[temp]]){
    temp++;
    }
    if(temp != n || rightMax[temp] != -1) ans[k] = rightMax[temp];
    }
    }
    return ans;
    }
    };