5 min read
development A walkthrough of "Two Sum": why checking every pair is wasteful, and how reframing the problem around a complement value lets a single HashMap pass find the answer in linear time.
A walkthrough of "Two Sum": why checking every pair is wasteful, and how reframing the problem around a complement value lets a single HashMap pass find the answer in linear time.
A walkthrough of "Valid Anagram": why sorting two strings works but isn't the cheapest option, and how a character frequency count gets you to linear time with constant extra space.
A walkthrough of "Group Anagrams": why comparing every pair of strings is too slow, and how turning each word into a canonical hash-map key groups them all in linear time.