uses global variable for hash. Passes all tests. O(n) complexity