Skip to content

Commit

Permalink
Merge pull request #288 from AbhiKamp/new
Browse files Browse the repository at this point in the history
Modify the Array OCT-24
  • Loading branch information
Ayu-hack authored Oct 25, 2024
2 parents 64b5831 + e35cb2d commit 55c03be
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions October 2024/Modify_the_Array_OCT24.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

class Solution:
def modifyAndRearrangeArr (self, arr) :
#Complete the function
k = len(arr)

for i in range(0,k):
if i == (k-1):
break
if (arr[i] != 0) & (arr[i+1] != 0) :
if arr[i]==arr[i+1]:
arr[i]=2*arr[i]
arr[i+1]=0
else:
continue
else:
continue
zero = arr.count(0)
for i in range(0,zero):
arr.remove(0)
arr.append(0)
return arr




if __name__ == "__main__":
t = int(input())
while t > 0:
arr = list(map(int, input().split()))
ob = Solution()
ans = ob.modifyAndRearrangeArr(arr)
print(*ans)
print("~")
t -= 1

0 comments on commit 55c03be

Please sign in to comment.