Hi: I was solving this problem http://codeforces.com/problemset/problem/451/B
my idea in brief is to sort the input and repeatedly check if an entry has been moved(call it a[i]) in the sort ,where it is know and which entry it was exchanged with(call it a[j] )and check every entry between a[i] and a[j] to double sure that if it is a segment that was reversed , lastly check the number of the reversed segments to print the answer.
Here is the code:
import java.util.*;
public class Main
{
public static void main (String args[]){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int unsort[]=new int[n];
int sort[]=new int[n];
for(int i=0;i<unsort.length;i++){
unsort[i]=sc.nextInt();
sort[i]=unsort[i];
}
Arrays.sort(sort);
int co=0;int counter=0,id=0,id2=1;
for(int i=0;i<unsort.length;i++){
if(unsort[i]!=sort[i]){
co++;
int in=Arrays.binarySearch(sort,unsort[i]);
if(sort[i]==unsort[in]&&sort[i+1]==unsort[in-1]){
int i2=i;int in2=in;boolean b=false;
while(i2++<=in2--){
if(sort[i2]!=unsort[in2]){b=true;break;}
}
if(b==false){
++counter;id=i;id2=in;
i=in;}
}
}
}
++id;++id2;
if(co==0){id=1;id2=1;}
System.out.println((counter==1||co==0)?"yes\n"+id+" "+id2:"no");
}
}
Edit:changed the blog as you said :)