Created
June 25, 2021 18:30
-
-
Save JonathanLalou/edaf294a3b905e580b7bf6565fcc5d8c to your computer and use it in GitHub Desktop.
This file contains hidden or 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.io.*; | |
import java.math.*; | |
import java.security.*; | |
import java.text.*; | |
import java.util.*; | |
import java.util.concurrent.*; | |
import java.util.function.*; | |
import java.util.regex.*; | |
import java.util.stream.*; | |
import static java.util.stream.Collectors.joining; | |
import static java.util.stream.Collectors.toList; | |
class Result { | |
/* | |
* Complete the 'minimumBribes' function below. | |
* | |
* The function accepts INTEGER_ARRAY q as parameter. | |
*/ | |
public static void minimumBribes(List<Integer> target) { | |
var counter = 0; | |
final int size = target.size(); | |
for (int i = 0; i < size; i++) { | |
final Integer item = target.get(i); | |
if (item - (i + 1) > 2) { | |
System.out.println("Too chaotic"); | |
return; | |
} | |
for (int j = Math.max(0, item - 2); j<i; j++){ | |
if(target.get(j) > item){ | |
counter++; | |
} | |
} | |
} | |
System.out.println(counter); | |
} | |
} | |
public class Solution { | |
public static void main(String[] args) throws IOException { | |
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); | |
int t = Integer.parseInt(bufferedReader.readLine().trim()); | |
IntStream.range(0, t).forEach(tItr -> { | |
try { | |
int n = Integer.parseInt(bufferedReader.readLine().trim()); | |
List<Integer> q = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" ")) | |
.map(Integer::parseInt) | |
.collect(toList()); | |
Result.minimumBribes(q); | |
} catch (IOException ex) { | |
throw new RuntimeException(ex); | |
} | |
}); | |
bufferedReader.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
many many many hours!!!!