Engaged Employer
public interface TwoSum { /** * Stores @param input in an internal data structure. */ public void store(int input); /** * Returns true if there is any pair of numbers in the internal data structure which * have sum @param test, and false otherwise. * For example, if the numbers 1, -2, 3, and 6 had been stored, * the method should return true for 4, -1, and 9, but false for 10, 5, and 0 */ public boolean test(int test); }
Anonymous
HashSet is insufficient for the "2x" case, i.e., if 6 is tested in the above example. There's only one 3, so it should return false, but the HashSet approach would return true. A HashMap with value == count could be used to handle this edge case (i.e., return true only if count > 1).
Check out your Company Bowl for anonymous work chats.