@@ -0,0 +1,944 @@
+package com.sunny.grokkingalgorithms.fasttrack.week8;%0A%0Aimport java.util.HashSet;%0Aimport java.util.Set;%0A%0A/**%0A * Created by sundas on 8/3/2018.%0A */%0Apublic class FindPairsEqualToK %7B%0A%0A%0A  /**%0A   *%0A   * @param input%0A   * @param k%0A   * @return%0A   */%0A  public static Set%3CSet%3CInteger%3E%3E findPairs(int%5B%5D input,int k)%7B%0A    Set%3CSet%3CInteger%3E%3E pairs = new HashSet%3C%3E();%0A    Set%3CInteger%3E lookup = new HashSet%3C%3E();%0A    for(int i : input)%7B%0A      lookup.add(i);%0A    %7D%0A    for(int i = 0 ; i %3C input.length ; i++)%7B%0A      int current = input%5Bi%5D;%0A      if(current %3C= k)%7B%0A        if(lookup.contains(k - current))%7B%0A          Set%3CInteger%3E pair = new HashSet%3C%3E();%0A          pair.add(current);%0A          pair.add(k - current);%0A          pairs.add(pair);%0A        %7D%0A      %7D%0A    %7D%0A    return pairs;%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%7B7,2,3,5,1,8,6%7D;%0A    System.out.println(findPairs(input,9));%0A  %7D%0A%0A%7D%0A

Find pairs that add up to k , O(n).