Numbers Replacement
Note: Start from the left end of the list.
sample input1
1 -2 3 -4 -5 6
sample output1
1 1 3 3 3 6
sample input2
1 11 -13 21 -19
sample output2
1 11 11 21 21
Num = [1, -2, 3, -4, -5, 6]
#Num = [1, 11, -13, 21, -19]
print("Original Array: ",Num)
for r in range(1,len(Num)):
if(Num[r]<0):
Num[r] = Num[r-1]
print("Modified Array: ",Num)
Comments
Leave a comment