We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
In Python (I tried the simplest thing, and it worked):
deflily_internal(a:list[int],reverse:bool=True):targets={n:ifori,ninenumerate(sorted(a,reverse=reverse))}swaps=0fori,ninenumerate(a):whilei!=targets[n]:# Swap the current value into the correct place.a[targets[n]],a[i]=n,a[targets[n]]swaps+=1n=a[i]returnswapsdeflilysHomework(a:list[int]):# lily_internal() is destructive, so send a copy the first time.returnmin(lily_internal(list(a),False),lily_internal(a,True))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Lily's Homework
You are viewing a single comment's thread. Return to all comments →
In Python (I tried the simplest thing, and it worked):