educative.io

Educative

Top-Down solution prev=-1 case

On running findLDSLength and findLDSLengthRev we want to include the pivot element.
Shouldn’t we just return result of adding element at currentIndex and not to run second possible option for first iteration? On findLDSLengthRev, e.g.:

if (prev == -1) {
    return 1 + findLDSLengthRev(nums, currentIndex-1, currentIndex);
}

Course: Grokking Dynamic Programming Patterns for Coding Interviews - Learn Interactively
Lesson: Longest Bitonic Subsequence - Grokking Dynamic Programming Patterns for Coding Interviews


Course: Grokking Dynamic Programming Patterns for Coding Interviews - Learn Interactively
Lesson: Longest Bitonic Subsequence - Grokking Dynamic Programming Patterns for Coding Interviews


Course: Grokking Dynamic Programming Patterns for Coding Interviews - Learn Interactively
Lesson: Longest Bitonic Subsequence - Grokking Dynamic Programming Patterns for Coding Interviews