You are viewing a single comment's thread. Return to all comments →
This Java 8 solution seems to work but fails two test cases on timed out, clearly I should find a solution with no nested loops
public static void minimumBribes(List<Integer> q) { // Write your code here int bribes = 0; for(int i=0; i< q.size();i++){ if(q.get(i) > i+1){ int bribes_temp = q.get(i) - (i+1); if (bribes_temp>2){ System.out.println("Too chaotic"); return; } bribes += bribes_temp; } else { int j = i; int bribes_temp = 0; while(++j<q.size()){ if(q.get(i)>q.get(j)){ if(++bribes_temp>2){ System.out.println("Too chaotic"); return; } } } bribes += bribes_temp; } } System.out.println(bribes); return; }
Seems like cookies are disabled on this browser, please enable them to open this website
New Year Chaos
You are viewing a single comment's thread. Return to all comments →
This Java 8 solution seems to work but fails two test cases on timed out, clearly I should find a solution with no nested loops