TransWikia.com

Can i know why my while loop is not working?

Stack Overflow Asked by Niranjan Kumar on November 18, 2021

This code should find the minimal number of moves required to obtain a strictly increasing sequence from the input, but it doesn’t.

def arrayChange(a):
    count = 0
    for i in range(len(a)):
        if a[i]<a[i-1] and i>0:
            while a[i]>a[i-1]:
                a[i]+=1
                count+=1
            
    return count

print(arrayChange([-1000, 0, -2, 0]))

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP