First negative integer in every window of size k | Love Babbar DSA sheet

Поділитися
Вставка
  • Опубліковано 3 жов 2024
  • If you wish to donate to the channel:
    Google pay UPI ID: adimantheboss123@okaxis
    -------------------------------------------------------------------------------------------------------------------------
    A great E-book on Data structures and algorithms written by a software engineer who has himself worked in MNC's. Its available for a very affordable price.
    Do check it out by clicking on the link below and boost your preparation.
    imojo.in/ajGui...
    -------------------------------------------------------------------------------------------------------------------------
    Problems:
    1. First negative integer in every window of size k:
    practice.geeks...
    solution:
    practice.geeks...
    -------------------------------------------------------------------------------------------------------------------------
    Playlist link:
    • 450 questions DSA sheet
    Link to the questions:
    drive.google.c...
    Connect with me on Linked in:
    / aditya-rajiv-0606491a5
    Connect with me on Instagram:
    / adi_rajiv
    #lovebabbardsasheet #stacks #queues #gfg #Coding #Fun #SDE #Placement #competitiveprogramming

КОМЕНТАРІ • 18

  • @royalsingh9400
    @royalsingh9400 Рік тому

    There is no need of j variable in this problem. Instead of j we can use (i-k)

  • @manthanpatil2268
    @manthanpatil2268 Рік тому +1

    Great explanation buddy!

  • @saniashaikh23b82
    @saniashaikh23b82 3 роки тому +2

    is this in O SPACE ? If not how can we optimise

    • @adityarajiv6346
      @adityarajiv6346  3 роки тому

      im not sure about further optimization. but yeah this solution works!

    • @ankitdas7532
      @ankitdas7532 3 роки тому +1

      This isn't O(1) space since we are using a queue to store the negative elements.
      For O(1) we can maintain a pointer which keeps track of next negative element . Once our window crosses that pointer , we move the pointer to next negative element.
      Code( accepted in gfg) :
      vector sol ;
      long long n =0 ; // pointer to negative elements
      while(n < N && A[n] >=0)n++;
      for(long long i=0 ; i=s && n=0)n++; // move pointer to next negative element
      }
      }
      return sol;

  • @rajaryansharma5001
    @rajaryansharma5001 3 роки тому +1

    Thanks!

    • @adityarajiv6346
      @adityarajiv6346  3 роки тому

      Your welcome 😀.
      Please share the channel with all your friends and subscribe 😀🙏.

  • @mdazazali7332
    @mdazazali7332 3 роки тому +1

    Can't we do this with vector..?

  • @ishanikasingh9321
    @ishanikasingh9321 3 роки тому

    Hi Aditya, queue works fine:
    vector printFirstNegativeInteger(long long int A[],
    long long int n, long long int k) {
    vector v;
    queue q;
    int i=0;
    int j=0;
    while(j

  • @avinashyadav8598
    @avinashyadav8598 3 роки тому +2

    Bhai explanation is not up to mark.

    • @adityarajiv6346
      @adityarajiv6346  3 роки тому +1

      okay is shall c if i can explain better next time

  • @mohammedwaseem8599
    @mohammedwaseem8599 3 роки тому +2

    Bro is competitive programming necessary??

    • @adityarajiv6346
      @adityarajiv6346  3 роки тому +2

      It's good way to build problem solving skills

  • @Priyanshukumar-yl5nh
    @Priyanshukumar-yl5nh Рік тому

    vector printFirstNegativeInteger(long long int a[],
    long long int n, long long int k) {
    vectorans;
    queueq;
    for(int i=0;i