code:
Only custom testcase running
Hello @myself.yash.srivastav,
The logic of your code is wrong.
-
The number of elements it is printing elements equal to k.
Example 1:
5
1 3 1 4 5
2
Output:
4 5
Expected Output:
3 3 4 5
Example 2:
5
1 3 1 4 5
4
Output:
1 3 4 5
Expected Output:
4 5 -
You are storing an element in array only if it greater than stack.top() which will not account for the window size i.e. k.
Example:
5
1 1 1 1 1
2
Output:
1
Expected Output:
1 1 1 1
Explanation:
Because the stack had only one element i.e. 1 and after displaying it. the stack will become empty causing the recursion to terminate.
Solution:
It is an application of the logic you have been taught in the video: Interview Problem - Maximum element in window of size k under Deque.
Suggestion:
Rewatch that video.
Hope, this would help.
Give a like if you are satisfied.
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.