Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class NewYearChaos {
private NewYearChaos() {}

static final String TOO_CHAOTIC_ERROR = "Too chaotic";
static final int NEW_YEAR_CHAOS_TOLERANCE = 2;


/**
* minimumBribesCalculate.
Expand All @@ -25,11 +27,13 @@ public static Integer minimumBribesCalculate(List<Integer> q) {
for (Integer value : q) {
int position = i + 1;

if (value - position > 2) {
if (value - position > NEW_YEAR_CHAOS_TOLERANCE) {
throw new IllegalStateException(TOO_CHAOTIC_ERROR);
}

List<Integer> fragment = q.subList(Math.min(Math.max(value - 2, 0), i), i);
List<Integer> fragment = q.subList(
Math.min(Math.max(value - NEW_YEAR_CHAOS_TOLERANCE, 0), i), i
);

for (Integer k : fragment) {
if (k > value) {
Expand Down