You are viewing a single comment's thread. Return to all comments →
O(n) in python by counting the number of flips between pairs of odd numbers
used modulo as boolean even%2 is equivalent to False and odd%2 is True
even%2
False
odd%2
True
total = 0 a = None flips = 0 for i in range(len(arr)): if arr[i]%2 and a == None: total += 1 a = i elif arr[i]%2: total += 1 flips += i - a a = None return 'NO' if total%2 else flips * 2
Seems like cookies are disabled on this browser, please enable them to open this website
Fair Rations
You are viewing a single comment's thread. Return to all comments →
O(n) in python by counting the number of flips between pairs of odd numbers
used modulo as boolean
even%2
is equivalent toFalse
andodd%2
isTrue