r/csinterviewproblems • u/tyroo • Dec 18 '15
[DP] Find all interpretations of a string
Given a map and a string find all interpretations of the string
{ "1": a,
"2": b,
"3": c,
...,
"26": z }
Example 1:
"112" - 3 interpretations
"al", "aab", "kb"
Example 2:
"345" - 1 interpretation
"cdf"Assume the mapping is already given to you and passed in as a parameter
Can be solved in O(n) runtime
Source: Big 4 interview
4
Upvotes
View all comments
Show parent comment
-1
u/zhay Dec 18 '15 edited Dec 18 '15
Dynamic programming is when you solve a problem by breaking it into smaller, overlapping subproblems and use the solutions for those subproblems to solve the original problem. That is the case here. Dynamic programming can often be applied to optimization and counting problems. This is a counting problem.
See: http://stackoverflow.com/a/6185005