Totient of a Number || Python
In this we are going to see a basic program to see Sliding Window Problem in Python Programming Language.


from collections import deque
dq = deque([])
a = [3, 4, 9, 1, -1, 10]
ans = []
n = len(a)
k = 2

for i in range(k):
    while dq and a[dq[-1]] < a[i]:
        dq.pop()
    dq.append(i)
ans.append(a[dq[0]])

for i in range(k, n):
    if dq[0] == i-k:
        dq.popleft()
    while dq and a[dq[-1]] < a[i]:
        dq.pop()
    dq.append(i)
    ans.append(a[dq[0]])
for i in ans:
    print(i, end=" ")

# Coded by Saahil

#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post