Skip to content

Instantly share code, notes, and snippets.

@arpanpreneur
Created March 17, 2020 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arpanpreneur/5484f6e580ac5ce7e0c4ede056227ebb to your computer and use it in GitHub Desktop.
Save arpanpreneur/5484f6e580ac5ce7e0c4ede056227ebb to your computer and use it in GitHub Desktop.
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