↧
Answer by vish4071 for Flip bits in array using python
Traverse the whole array. Keep a count in the following way:Do +1 for every 0 bit encountered.Do -1 for every 1.If this count reaches -ve at any stage, reset it to 0. Keep track of max value of this...
View ArticleAnswer by juanpa.arrivillaga for Flip bits in array using python
Cleaned up and made Pythonic arr1 = [1, 0, 0, 1, 0, 0, 1, 0]arr2 = [1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1]arr3 = [0,0,0,1,1,0,1,0,1,1,0,0,1,1,1]def maximum_ones(arr):""" Returns max...
View ArticleFlip bits in array using python
You are given an integer array with N elements: d[0], d[1], ... d[N - 1]. You can perform AT MOST one move on the array: choose any two integers [L, R], and flip all the elements between (and...
View Article