Identifying the counting pattern
The counting technique can only be used to solve some specific problems. These are generally easy or medium problems involving arrays or strings where we must remember some or all the occurrences of a data item to use it later. In most cases, applying the counting technique does not solve the problem; it only computes the frequency map. The frequency map is then used as an input along with other problem contexts to partially or completely solve the problem.
If the problem statement or its solution follows the generic template below, it can be solved by applying the counting technique.
Template:
Given an iterable sequence of data, compute the frequency map of its items and use it to solve the problem.
Liking the course? Check our discounted plans to continue learning.