Count number of 1 s in the array after N moves | Java implementation of the above approach ; 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 ++ ; count number of 1 's ; Driver Code ; Initialize all elements to 0
class GFG { static int countOnes ( int arr [ ] , int N ) { for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = i ; j <= N ; j ++ ) { if ( j % i == 0 ) { if ( arr [ j - 1 ] == 0 ) { } else { } } } } int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 1 ) { } } return count ; } public static void main ( String [ ] args ) { int arr [ ] = new int [ 10 ] ; int ans = countOnes ( arr , N ) ; System . out . println ( ans ) ; } }