r/csinterviewproblems • • 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

8 comments sorted by

View all comments

Show parent comment

3

u/abstractwhiz Dec 19 '15

This the first time I've heard such a statement, but after some thinking, I can kinda see your point. .

But it ultimately seems like a pointless distinction. In both cases, solving the problem comes down to formulating a recurrence and using a cache to avoid pointless repetition. I don't think they should be treated as fundamentally different things just because one class of recurrences has min/max operators and the other does not.