text: Find the player who is the last to remove any character from the beginning of a Binary String | Java program for the above approach ; Function to find the player who loses the game ; Moves for the first player ; Moves for the second player ; Iterate over array of Strings ; Check if the first and last character are the same ; Check if String start and end with character '0' ; If first player have less moves ; Driver Code ; Given array of Strings ; Function Call
code: import java . util . * ; class GFG { static void findPlayer ( String str [ ] , int n ) { int move_first = 0 ; int move_sec = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( str [ i ] . charAt ( 0 ) == str [ i ] . charAt ( str [ i ] . length ( ) - 1 ) ) { if ( str [ i ] . charAt ( 0 ) == 48 ) move_first ++ ; else move_sec ++ ; } } if ( move_first <= move_sec ) { System . out . print ( " Player ▁ 2 ▁ wins " ) ; } else { System . out . print ( " Player ▁ 1 ▁ wins " ) ; } } public static void main ( String [ ] args ) { String str [ ] = { "010" , "101" } ; int N = str [ 0 ] . length ( ) ; findPlayer ( str , N ) ; } }