Created
December 18, 2018 22:39
-
-
Save randyhbh/9a9f594fbcca378578208711b89f610a to your computer and use it in GitHub Desktop.
This method is the answer to the problem of "New Year's Chaos" in which he receives an int [] and must answer how many bribes there have been; If a person bribes more than 2 times it is total chaos.
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
static void minimumBribes(int[] q) { | |
int ans=0; | |
for(int i=q.length -1; i >= 0 ; i--) { | |
if (q[i] - (i+1) > 2) { | |
System.out.println("Too chaotic"); | |
return; | |
} | |
for (int j = Integer.max(0, q[i] - 2); j < i; j++) | |
if (q[j] > q[i]) ans++; | |
} | |
System.out.println(ans); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment