Count number of 1 s in the array after N moves | Function to count number of 1 's in the array after performing N moves ; If index is multiple of move number ; arr [ j - 1 ] = 1 Convert 0 to 1 ; arr [ j - 1 ] = 0 Convert 1 to 0 ; Count number of 1 's ; count += 1 count number of 1 's ; Driver Code ; Initialize all elements to 0
def countOnes ( arr , N ) : NEW_LINE INDENT for i in range ( 1 , N + 1 , 1 ) : NEW_LINE INDENT for j in range ( i , N + 1 , 1 ) : NEW_LINE INDENT if ( j % i == 0 ) : NEW_LINE INDENT if ( arr [ j - 1 ] == 0 ) : NEW_LINE else : NEW_LINE DEDENT DEDENT DEDENT count = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( arr [ i ] == 1 ) : NEW_LINE DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 0 for i in range ( 10 ) ] NEW_LINE ans = countOnes ( arr , N ) NEW_LINE print ( ans ) NEW_LINE DEDENT