Created
March 17, 2020 12:19
-
-
Save arpanpreneur/5484f6e580ac5ce7e0c4ede056227ebb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class Bowl { | |
static int getModifiedBowl(int[] marbles) { | |
for (int i = marbles.length - 1; i >= 0; i--) { | |
if (marbles[i] < 9) { | |
// This one is not required here, but in online compiler it might ask to modify the original array | |
// sent to the funtion | |
if (i != marbles.length-1) { | |
marbles[i+1] = 0; | |
} | |
return i+1; | |
} | |
} | |
return 0; | |
} | |
public static void main(String args[]) { | |
Scanner sc = new Scanner(System.in); | |
int N = sc.nextInt(); | |
int[] marbles = new int[N]; | |
for (int i = 0; i < N; i++) { | |
marbles[i] = sc.nextInt(); | |
} | |
System.out.println(getModifiedBowl(marbles)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment