@@ -0,0 +1,2467 @@
+import java.io.BufferedReader;%0Aimport java.io.IOException;%0Aimport java.io.InputStreamReader;%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0A%0A// https://www.hackerrank.com/challenges/new-year-chaos/problem%0Apublic class NewYearChaos %7B%0A%0A    private static final String SPACE = %22 %22;%0A    private static final String TOO_CHAOTIC = %22Too chaotic%22;%0A%0A    private static List%3Cint%5B%5D%3E readQueues() throws IOException %7B%0A        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) %7B%0A            int testCases = Integer.parseInt(reader.readLine());%0A            List%3Cint%5B%5D%3E queues = new ArrayList%3C%3E(testCases);%0A            for (int i = 0; i %3C testCases; i++) %7B%0A                reader.readLine(); // Ignore this line%0A                String%5B%5D split = reader.readLine().split(SPACE);%0A                int%5B%5D queue = Arrays.stream(split).mapToInt(Integer::parseInt).toArray();%0A                queues.add(queue);%0A            %7D%0A            return queues;%0A        %7D%0A    %7D%0A%0A    private static void checkQueueIsPossible(int%5B%5D queue) %7B%0A        for (int i = 0; i %3C queue.length; i++) %7B%0A            int correctedIndex = i + 1;%0A            int currentPosition = queue%5Bi%5D;%0A            int positionDifference = currentPosition - correctedIndex;%0A            if (positionDifference %3E 2) %7B%0A                throw new IllegalStateException(TOO_CHAOTIC);%0A            %7D%0A        %7D%0A    %7D%0A%0A    private static int getMinSwitches(int%5B%5D queue) %7B%0A        int minSwitches = 0;%0A        for (int i = queue.length - 1; i %3E= 0; i--) %7B%0A            int initialPosition = queue%5Bi%5D;%0A            // if someone pass me it should be maximum in my initial position - 2.%0A            int maxBribedPosition = (initialPosition - 2 %3E 0) ? initialPosition - 2: 0;%0A            for (int j = maxBribedPosition; j %3C i; j++) %7B%0A                int first = queue%5Bj%5D;%0A                boolean wasBrived = first %3E initialPosition;%0A                minSwitches += wasBrived ? 1: 0;%0A            %7D%0A        %7D%0A        return minSwitches;%0A    %7D%0A%0A    public static void main(String%5B%5D args) throws IOException %7B%0A        List%3Cint%5B%5D%3E queues = readQueues();%0A        for (int%5B%5D queue : queues) %7B%0A            try %7B%0A                checkQueueIsPossible(queue);%0A                int minSwitches = getMinSwitches(queue);%0A                System.out.println(minSwitches);%0A            %7D catch (IllegalStateException e) %7B%0A                System.out.println(e.getMessage());%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A

Add solution for New Year Chaos problem.