Couldn’t get few things cleared in this lecture.
First Negative Integer in Window K
I am not been able to understand the code after line 20.
@vikrantdhanwadia_ba234822f246017c After line 20 we have used a loop to starting from i = 2 bcoz when i = 2 we have got our first window of size k . So from i = 2; we need to start printing our answer so if the queue is empty then its simple that we dont have any negative element in current window of k.
So print '0’but if there is a element that means that will be the first negative in that subarray bcoz of the functionality of queue(FIFO).
Note : we are storing indexes in the queue not Elements.
Now we got a condition if(queue.peek() <= i -k)
this conditon tells us that whatever is on the top of queue we cant conisder that bcoz it will be out of the size of window bcoz i - k will tells us the starting point of current k size subarray if it is greater that than index at top of queue that means that index is no longer needed and we will dequeue that index till we get in the range of the k size subarray.(used while loop for this)
And the last condition is totally obvious that we are adding every negative element’s index in the queue while traversing.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.