Just finished OA but didn't pass all the test cases.
Tho I finished doing this, still wanna know how to solve Q1...
Hacker's Team
Similar to https://leetcode.com/problems/longest-increasing-subsequence/
The transformation is there are 2 arrays of the same length.
len(arr1) = len(arr2) = n
for each index i (0<=i<n), you can either choose arr1[i] or arr2[i] to form a non-decreasing array.
The function needs to return the max. j-i+1 if we perform the above-mentioned operation to form a valid array at every index x in [i,j] (both inclusive)
Test case:
arr1 = [3,2,7,4]
arr2 = [5,3,2,6]
we can either choose [arr1[1], arr2[2], arr1[3]] or [arr1[1], arr2[2], arr2[3]] to form [2,2,4] or [2,2,6]
output: 3
My intuition is DP, but don't know how to find the recurrrence.
My explanation may be unclear, let me know if you find this confusing.
Maximum path sum
https://leetcode.com/problems/binary-tree-maximum-path-sum/
I coded out the DFS solution but got TLE in some test cases.
BFS solution should be accepted.
Any thoughts about first question please share below, thanks!