You are given a binary tree node definition:
TreeNode { int val; TreeNode left; TreeNode right; }
Answer the following two algorithmic questions.
Implement a function that returns the values of the tree level by level from bottom to top.
root
(possibly
null
)
Example
Tree:
1
2
(children:
4
,
5
)
3
(right child:
6
)
Output: [[4,5,6],[2,3],[1]]
Given a string s, return the length of the longest subsequence of s that is a palindrome.
s
Example
"bbbab"
4
(one LPS is
"bbbb"
)
0 <= number_of_nodes <= 10^5
for the tree
1 <= |s| <= 2000
for LPS