@@ -0,0 +1,1594 @@
+//https://www.hackerrank.com/challenges/almost-sorted%0Aimport java.io.*;%0A%0Apublic class Solution %7B%0A  public static void main(String%5B%5D args) throws IOException %7B%0A    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));%0A%0A    //Get input%0A    final int N = Integer.parseInt(br.readLine());%0A    final int%5B%5D arr = new int%5BN%5D;%0A    String%5B%5D line = br.readLine().split(%22 %22);%0A    for(int i = 0; i %3C N; ++i)%7B%0A      arr%5Bi%5D = Integer.parseInt(line%5Bi%5D);%0A    %7D%0A    %0A    //Print output%0A    System.out.print(solve(arr, N));%0A  %7D%0A  %0A  private static String solve(final int%5B%5D A, final int N)%7B%0A    int l = 0;%0A    int r = N - 1;%0A    %0A    //Check for out of place index from the left%0A    while(l %3C r && A%5Bl%5D %3C= A%5Bl+1%5D)%7B%0A      ++l;%0A    %7D%0A    %0A    //Check if array already sorted%0A    if(l == r)%7B%0A      return %22yes%22;%0A    %7D%0A    %0A    //Check for out of place index from the right%0A    while(r %3E l && A%5Br%5D %3E= A%5Br-1%5D)%7B%0A      --r;%0A    %7D%0A    %0A    //Check if swapping or reversing would NOT sort the array%0A    if((l %3E 0 && A%5Br%5D %3C A%5Bl-1%5D) %7C%7C (r %3C N-1 && A%5Bl%5D %3E A%5Br+1%5D))%7B%0A      return %22no%22;%0A    %7D%0A        %0A    //Check if we're dealing with a reversal%0A    int m;%0A    for(m = l+1; m %3C r && A%5Bm%5D %3E= A%5Bm+1%5D; ++m)%7B%7D%0A    if(m == r)%7B%0A      return %22yes%5Cn%22 + ((r-l %3C 2) ? %22swap %22 : %22reverse %22) + (l+1) + %22 %22 + (r+1);%0A    %7D%0A    %0A    //Check if we're NOT dealing with a swap%0A    if(m-l %3E 1 %7C%7C A%5Bl%5D %3C A%5Br-1%5D %7C%7C A%5Br%5D %3E A%5Bl+1%5D)%7B%0A      return %22no%22;%0A    %7D%0A    %0A    //Check if we're dealing with a swap%0A    for(int k = r-1; m %3C k && A%5Bm%5D %3C= A%5Bm+1%5D; ++m)%7B%7D%0A    return (r-m %3E 1) ? %22no%22 : %22yes%5Cnswap %22 + (l+1) + %22 %22 + (r+1);%0A  %7D%0A%7D%0A

Create almost-sorted.java