- When you need to count number of pairs in a given list, you can use a map (e.g. HashMap<Integer, Integer>) to put the unique items then increment the counter when the same item appears again. Use modulo after incrementing the count to determine if count is a pair (e.g. n % 2 == 0 then it is a pair). (the ‘Unique Tracker Technique’)
- When you need to count something that requires a certain condition involving equilibrium (or a valley) then use an index. In this example, a valley usually will have an exit point of ‘up’ which will hit the index. With that condition, you can count the number of valleys based on that. (the ‘Breaking Condition’ technique)
- Rather than scanning every character in a big string, you can divide the small string first then multiply the output to how many instances it should have appeared in the big string. (the ‘Divide and Conquer’ technique)