@@ -0,0 +1,1212 @@
+package com.sunny.grokkingalgorithms.fasttrack.week6;%0A%0Aimport java.util.Arrays;%0A%0A/**%0A * Created by sundas on 7/24/2018.%0A */%0Apublic class Median %7B%0A%0A  /*%0A  The median%0AThe median is the middle number. To calculate the median of any set of numbers, you need to write the numbers in order.%0A%0ATo find the median number:%0A%0APut all the numbers in numerical order.%0AIf there is an odd number of results, the median is the middle number.%0AIf there is an even number of results, the median will be the mean of the two central numbers.%0A   */%0A%0A  /**%0A   *%0A   * @param input%0A   * @return%0A   */%0A  public static double findMedian(int%5B%5D input)%7B%0A    double median = -1;%0A    Arrays.sort(input);%0A    int length = input.length;%0A    if(length%252 != 0)%7B%0A      median = input%5B(length - 1)/2%5D;%0A    %7D%0A    else%7B%0A      int mid1 = input%5B(length - 1)/2 + 1%5D;%0A      int mid2 = input%5B(length - 1)/2%5D;%0A      median = (mid1 + mid2)/2;%0A    %7D%0A    return median;%0A  %7D%0A%0A  /**%0A   *%0A   * @param args%0A   */%0A  public static void main(String%5B%5D args) %7B%0A    int%5B%5D input = new int%5B%5D%7B9, 13, 9, 11, 9, 13, 11, 9, 10, 8, 11%7D;%0A    System.out.println(findMedian(input));%0A    input = new int%5B%5D%7B5,  11,  12,  4,  8,  21%7D;%0A    System.out.println(findMedian(input));%0A  %7D%0A%0A%7D%0A

Find median. Brute force O(nlogn)