Here are some standard types of questions on a string that one faces in their coding journey and how to think of approaching any string-based question by categorizing them into 5 types.

  1. Type I: When it is required to validate the string or to find something in the string. In such questions, it is required to traverse the string like an array whilst validating or finding something.

    Problems of this type:

  2. Type II When you need to search a substring/another string. Most of such questions can be solved using pointer-based approach. One/more pointer approach.

    Problems of this type:

  3. Type III When you need to find the smallest/largest/ conditional substring from the given string, the sliding window approach is the way to go. An example of such a question would be: find the longest substring without repeating the character.

    Problems on this type:

  4. Type IV When the problem needs you to find all the permutations of a string, backtracking is the most common approach for such problems.

    Problems on this type:

  5. Type V Whenever the above approaches do not fit, its most likely a question on Dynamic Programming. Try to identify the subproblem and solve using DP.

    Problems on this type: