You are viewing a single comment's thread. Return to all comments →
public static void minimumBribes(List<Integer> q) { // Write your code here int bribes = 0; for(int i = q.size()-2;i>=0;i--){ int diff = q.get(i) - (i +1); if(diff > 2){ System.out.println("Too chaotic"); return; } while(diff-- > 0){ bribes++; int temp = q.get(i+1); q.set(i+1,q.get(i)); q.set(i,temp); if(diff == 1) i++; } } System.out.println(bribes); }
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 →