Grokking Dynamic Programming Patterns for Coding Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
Subsequence Pattern Matching
On this page

Problem Statement

Try it yourself

Problem Statement

Given a string and a pattern, write a method to count the number of times the pattern appears in the string as a subsequence.

Example 1: Input: string: <span style="color:blue">"baxmx"</span>, pattern: <span style="color:blue">"ax"</span>
Output: <span style="color:green">2</span>
Explanation: {b<span style="color:red">ax</span>mx, b<span style="color:red">a</span>xm<span style="color:red">x</span>}.

Example 2:

Input: string: <span style="color:blue">"tomorrow"</span>, pattern: <span style="color:blue">"tor"</span>
Output: <span style="color:green">4</span>
Explanation: Following are the four occurences: {<span style="color:red">to</span>mo<span style="color:red">r</span>row, <span style="color:red">to</span>mor<span style="color:red">r</span>ow, <span style="color:red">t</span>om<span style="color:red">or</span>row, <span style="color:red">t</span>om<span style="color:red">o</span>r<span style="color:red">r</span>ow}.

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Like the course? Get enrolled and start learning!

On this page

Problem Statement

Try it yourself