Given binary tree
{1,#,2,3}
,1 \ 2 / 3
[1,3,2]
.
{1,#,2,3}
,1 \ 2 / 3
[1,3,2]
."((()))", "(()())", "(())()", "()(())", "()()()"
{1,#,2,3}
,1 \ 2 / 3
[3,2,1]
.[1,2,3]
have the following permutations:[1,2,3]
, [1,3,2]
, [2,1,3]
, [2,3,1]
, [3,1,2]
, and [3,2,1]
.
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.
Note: You can only move either down or right at any point in time.
Apply DFS first failed on time limitation, then adopted DP with 2 dimension matrix passed OJ, finally refector code to use 1 dimension rotational array
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
For example,
Consider the following matrix:
[
[1, 3, 5, 7],
[10, 11, 16, 20],
[23, 30, 34, 50]
]
For an O (rows * cols) solution is too simple to meet the interviewer’s expectation. So what is the better solution should be? Binary search should be a good tool when I face search problem, however, how BS could be apply in matrix? if we regard 0 as start point, total_cols*total_rows-1 as the end point to look the matrix as a array then we can apply BS. However, how could we convert the position to row_NO and col_NO? We know row_NO * total_cols+col_NO=position, So in programming row_NO=postion/total_cols, col_NO=postion%total_cols. then we can adapt this feature in our program to apply binary search to get O(log(cols+rows)) search
[1,1,1,2,2,3]
,5
, and A is now [1,1,2,2,3]
.3
,[ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ] ]