def assert(x) raise x.inspect unless x end class Solution # time: O(n) # space: O(n) def self.run(items, k) nums = {} for i in (0...items.size) nums[items[i]] = true return true if nums[k - items[i]] end false end end =begin h |4|7|1|-3|2| =end assert(Solution.run([4, 7, 1, -3, 2], 5)) assert(!Solution.run([], 5)) assert(!Solution.run([1], 5)) assert(Solution.run([1,-3,7,8], 5)) assert(Solution.run([3,1,3], 6)) puts "Yay!"