We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
hii fellow coders below is my logic which i use to min swap (basically I initially comparing my first value to second and if my value is found big then I will traverse again the array to see there is a more less value which is present in the array or not if we found then we will swap . but somwhere Iam wrong please help me guys
int n=arr.size()-1;
int count=0;
for(int i=r;iarr.get(i+1)){
int min=i+1;
int j=min;
while(jarr.get(j)){
min=j;
}
j++;
}
if(arr.get(i)>arr.get(min)){
int temp=arr.get(i);
arr.add(i, arr.get(min));
arr.add(min,temp);
count++;
}
}
}
return count;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Lily's Homework
You are viewing a single comment's thread. Return to all comments →
hii fellow coders below is my logic which i use to min swap (basically I initially comparing my first value to second and if my value is found big then I will traverse again the array to see there is a more less value which is present in the array or not if we found then we will swap . but somwhere Iam wrong please help me guys
int n=arr.size()-1; int count=0; for(int i=r;iarr.get(i+1)){ int min=i+1; int j=min; while(jarr.get(j)){ min=j; } j++; } if(arr.get(i)>arr.get(min)){ int temp=arr.get(i); arr.add(i, arr.get(min)); arr.add(min,temp); count++;
} }
} return count;
}