package com.sunny.grokkingalgorithms.gfg.vmw;

/**
 * Created by sundas on 4/10/2018.
 */
public class ReverseAString {

  /*
  Given an array (or string), the task is to reverse the array/string.

Examples :

Input  : arr[] = {1, 2, 3}
Output : arr[] = {3, 2, 1}

Input :  arr[] = {4, 5, 1, 2}
Output : arr[] = {2, 1, 5, 4}
   */

  /**
   *
   * @param input
   * @return
   */
  public static int[] reverse(int[]  input){
    int i = 0;
    int j = input.length - 1;
    while(i < j){
      int temp = input[i];
      input[i] = input[j];
      input[j] = temp;
      i++;
      j--;
    }
    return input;
  }


  /**
   *
   * @param args
   */
  public static void main(String[] args) {
    int[] input = new int[]{1, 2, 3};
    int[] output =  reverse(input);
    for(int i = 0 ; i < output.length ; i++){
      System.out.print(output[i] + " ");
    }
    System.out.println();
    input = new int[]{4, 5, 1, 2};
    output =  reverse(input);
    for(int i = 0 ; i < output.length ; i++){
      System.out.print(output[i] + " ");
    }
  }
}

@@ -609,16 +609,304 @@
 t;%0A  %7D%0A%0A
+  public static String reverse(String str)%7B%0A    char%5B%5D input = str.toCharArray();%0A    int i = 0;%0A    int j = input.length - 1;%0A    while(i %3C j)%7B%0A      char tmp = input%5Bi%5D;%0A      input%5Bi%5D = input%5Bj%5D;%0A      input%5Bj%5D = tmp;%0A      i++;%0A      j--;%0A    %7D%0A    return String.valueOf(input);%0A  %7D%0A%0A
 %0A  /**%0A 
@@ -1326,14 +1326,169 @@
 ;%0A    %7D%0A
+    String str = %22testuser%22;%0A    System.out.println(%22%22);%0A    String rev = reverse(str);%0A    System.out.println(rev);%0A    System.out.println(reverse(rev));%0A
   %7D%0A%7D%0A

reverse a string.