Count the number of times a pattern appears in a given string as a subsequence
Given a string, count the number of times a given pattern appears in it as a subsequence.
Ace your Coding Interview
Get hired by top tech companies with our comprehensive interview preparation.
Get StartedGiven a string, count the number of times a given pattern appears in it as a subsequence.
The longest alternating subsequence is a problem of finding a subsequence of a given sequence in which the elements are in alternating order and in which the sequence is as long as possible.
Given an unlimited supply of coins of given denominations, find the total number of distinct ways to get the desired change.
Coin change-making problem: Given an unlimited supply of coins of given denominations, find the minimum number of coins required to get the desired change.
Given a rod of length n, find the optimal way to cut the rod into smaller rods to maximize the product of each of the smaller rod’s price. Assume each rod of length i has price i.
Given a rod of length n and a list of prices of rods of length i, where 1 <= i <= n, find the optimal way to cut the rod into smaller rods to maximize profit.
Given a positive integer n, count all n–digit binary numbers without any consecutive 1’s.
Given a set of positive integers S, partition set S into two subsets, S1 and S2, such that the difference between the sum of elements in S1 and the sum of elements in S2 is minimized.
Given a set of positive integers and an integer s, is there any non-empty subset whose sum to s.
Given a set of positive integers, find if it can be divided into two subsets with equal sum. The partition problem is a special case of the subset sum problem, which itself is a special case of the knapsack problem.
In the 0–1 Knapsack problem, we are given a set of items, each with a weight and a value, and we need to determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible.
Given an M × N matrix where each cell has a non-negative cost associated with it, count the number of paths to reach the last cell (M-1, N-1) of the matrix from its first cell (0, 0) such that the path has given cost.