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

0% completed

Vote For New Content
The brute force solution seems to be incorrect? Doesn't it return False prematur...

Gary

Jul 4, 2022

The brute force solution seems to be incorrect? Doesn't it return False prematurely if the first letter of p doesn't match the first letters of m and n?

If I call find_SI("abc", "def", "cabdeccf"), it returns False even though "abc" and "def" are interleaved in "cabdeccf"

0

0

Comments
Comments
Design Gurus
Design Gurus3 years ago

If the first letter is not matched, it should return false.

If the first letter is not matched, we can't form 'p' with 'm' and 'n' keeping the order of letters preserved.

'p' can't have extra characters. As the problems says, we are checking if 'p' is formed by charac...

G
Gary 3 years ago

Ah I see. It wasn't clear to me that p can't have extra letters.

On this page