Posts

Showing posts from May, 2018

Hash Table (Part 2)

Image
Target May 20th to finish Frequency Count 299 Bulls and Cows      If two chars  matches, add aCnt, otherwise, increase their frequency in hashMap and process bCnt in second pass (add the minimum of the two same digits frequency to B count) 554 Brick Wall      Count the frequency of each breakpoint length. And find the max frequency breakpoint length maxVal, then the wall.size() - maxVal will be the minimum number of bricks got cut. 447 Number of Boomerangs      Idea: Use each point as the first point of the tuple, calculate the distance from all the other points to this point. Any two points that have the same distance with the current  point can construct a tuple that is boomerangs (n * (n - 1) / 2). And we have two answers for the two points (say b, c) that has same distance with a (i.e: a,b,c and a,c,b). We use hash map to calculate the distance from all the other points to t...