Skip to content

Instantly share code, notes, and snippets.

@dennermiranda
Created April 10, 2017 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dennermiranda/4e644345d9e6830a3a58819d551fd2c2 to your computer and use it in GitHub Desktop.
Save dennermiranda/4e644345d9e6830a3a58819d551fd2c2 to your computer and use it in GitHub Desktop.
import java.util.HashMap;
public class Interview {
public static boolean sum(int[] A, int b){
HashMap<Integer, Integer> hash = new HashMap<Integer, Integer>();
for (int i = 0; i<A.length; i++){
hash.put(A[i], i);
}
for (int i = 0; i<A.length; i++){
if(hash.get(b-A[i])!= null && hash.get(b-A[i]) != i){
return true;
}
}
return false;
}
public static void main(String[] args) {
int [] A = {2, 2, 2, 2, 1, 2, 1, 2, 1, 3};
System.out.println(sum(A, 200));
System.out.println(sum(A, 4));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment