21. Sliding Window Maximum Using Deque
Required Input:
arr = [1, 3, -1, -3, 5, 3, 6, 7], k = 3Expected Output:
[3, 3, 5, 5, 6, 7]
Code In Python
from collections import deque
def sliding_window_max(arr, k):
# Write your logic here
pass
# Prefilled input
arr = [1, 3, -1, -3, 5, 3, 6, 7]
k = 3
print(sliding_window_max(arr, k))
Run Code?
Click Run Button to view compiled output
22. First Non-Repeating Character in a Stream
Required Input:
stream = 'aabc'Expected Output:
['a', 'a', 'b', 'b']
Code In Python
from collections import deque
def first_non_repeating(stream):
# Write your logic here
pass
# Prefilled input
stream = "aabc"
print(first_non_repeating(stream))
Run Code?
Click Run Button to view compiled output
23. Implement a Stack Using Two Queues
Required Input:
operations = ['push 10', 'push 20', 'pop', 'top']Expected Output:
[20, 10]
Code In Python
def stack_using_queues(operations):
# Write your logic here
pass
# Prefilled input
operations = ['push 10', 'push 20', 'pop', 'top']
print(stack_using_queues(operations))
Run Code?
Click Run Button to view compiled output
24. Queue Reversal
Required Input:
queue = [1, 2, 3, 4, 5]Expected Output:
[5, 4, 3, 2, 1]
Code In Python
def reverse_queue(queue):
# Write your logic here
pass
# Prefilled input
queue = [1, 2, 3, 4, 5]
print(reverse_queue(queue))
Run Code?
Click Run Button to view compiled output
25. Find the Middle Element of a Stack
Required Input:
stack = [1, 2, 3, 4, 5]Expected Output:
3
Code In Python
def find_middle(stack):
# Write your logic here
pass
# Prefilled input
stack = [1, 2, 3, 4, 5]
print(find_middle(stack))
Run Code?
Click Run Button to view compiled output
26. Check for Balanced Parentheses Using Stack
Required Input:
s = '{[()()]}'Expected Output:
True
Code In Python
def is_balanced(s):
# Write your logic here
pass
# Prefilled input
s = '{[()()]}'
print(is_balanced(s))
Run Code?
Click Run Button to view compiled output
27. Reverse a Stack Using Recursion
Required Input:
stack = [1, 2, 3, 4, 5]Expected Output:
[5, 4, 3, 2, 1]
Code In Python
def reverse_stack(stack):
# Write your logic here
pass
# Prefilled input
stack = [1, 2, 3, 4, 5]
print(reverse_stack(stack))
Run Code?
Click Run Button to view compiled output
28. Implement a Stack with Max Function
Required Input:
operations = ['push 5', 'push 10', 'push 20', 'getMax', 'pop', 'getMax']Expected Output:
[20, 10]
Code In Python
def stack_with_max(operations):
# Write your logic here
pass
# Prefilled input
operations = ['push 5', 'push 10', 'push 20', 'getMax', 'pop', 'getMax']
print(stack_with_max(operations))
Run Code?
Click Run Button to view compiled output
29. Implement a Queue Using Deques
Required Input:
operations = ['enqueue 10', 'enqueue 20', 'dequeue', 'enqueue 30']Expected Output:
[10, 30]
Code In Python
from collections import deque
def queue_using_deques(operations):
# Write your logic here
pass
# Prefilled input
operations = ['enqueue 10', 'enqueue 20', 'dequeue', 'enqueue 30']
print(queue_using_deques(operations))
Run Code?
Click Run Button to view compiled output
30. Sort a Queue Using Recursion
Required Input:
queue = [5, 2, 9, 1, 3]Expected Output:
[1, 2, 3, 5, 9]
Code In Python
def sort_queue(queue):
# Write your logic here
pass
# Prefilled input
queue = [5, 2, 9, 1, 3]
print(sort_queue(queue))
Run Code?
Click Run Button to view compiled output


