0% found this document useful (0 votes)
19 views

Code 1

This Python code takes in an integer n and a list of integers as input, iterates through the list from the end to start, sets elements in an output list ans to 1 if the current maximum seen is greater than 0, and decrements the maximum, printing the final ans list.

Uploaded by

Md.Amdad Hossain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Code 1

This Python code takes in an integer n and a list of integers as input, iterates through the list from the end to start, sets elements in an output list ans to 1 if the current maximum seen is greater than 0, and decrements the maximum, printing the final ans list.

Uploaded by

Md.Amdad Hossain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

1.

def solve():
2. n = int(input())
3. a = list(map(int, input().split()))
4. ans = [0] * n
5. cur = 0
6. for i in reversed(range(n)):
7. cur = max(cur, a[i])
8. if cur > 0:
9. ans[i] = 1
10. cur -= 1
11. print(*ans)
12.  
13. t = int(input())
14. for _ in range(t):
15. solve()

You might also like