Python Program to Rearrange the array in alternating positive and negative items with O(1) extra space
Login/Signup to comment
Login/Signup to comment
Get Hiring Updates right in your inbox from PrepInsta
a=[2, 3, -4, -1, 6, -9]
p=0
for i in range(0,len(a)):
if a[i]<0:
a[p],a[i]=a[i],a[p]
p+=2
print(a)
Kindly refer to our discord community for all your technical doubts.