You are viewing a single comment's thread. Return to all comments →
public static void minimumBribes(List q) { // Write your code here
int arr[] = new int[q.size()]; int j=0; int minBribe = 0; for(Integer i : q){ arr[j++] = i; } for(int i=0; i < arr.length-1;i++){ if(arr[i] > i+1){ // System.out.println(arr[i]+"here"); int diff = arr[i] - (i +1 ); if(diff <= 2 ){ minBribe += diff; }else{ System.out.println("Too chaotic"); return; } } else if(arr[i] > arr[i+1] ){ // System.out.println(arr[i]+"*"); minBribe += 1; } } System.out.println(minBribe); }
Can anyone help me here. and explain where I am going wrong here. in what case my solution is failing.
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 →
public static void minimumBribes(List q) { // Write your code here
Can anyone help me here. and explain where I am going wrong here. in what case my solution is failing.