221. Maximal Square
Problem description:
Given a 2D binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area.
Example:1
2
3
4
5
6
7
8Input:
1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0
Output: 4
Problem description:
Given a 2D binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area.
Example:1
2
3
4
5
6
7
8Input:
1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0
Output: 4
Problem description:
Given a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle containing only 1’s and return its area.
Example:1
2
3
4
5
6
7
8Input:
[
["1","0","1","0","0"],
["1","0","1","1","1"],
["1","1","1","1","1"],
["1","0","0","1","0"]
]
Output: 6
Problem description:
Given n non-negative integers representing the histogram’s bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.
Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3].
The largest rectangle is shown in the shaded area, which has area = 10 unit.
Problem description:
Given two words word1 and word2, find the minimum number of operations required to
convert word1 to word2.
You have the following 3 operations permitted on a word:
——已推——
Walmart Sam’s Club Technology 8/14, 8/29 tech interview
https://goo.gl/BWxxLS
Problem description:
Given a linked list, swap every two adjacent nodes and return its head.
For example,
Given 1->2->3->4, you should return the list as 2->1->4->3.
Problem description:
Sort a linked list using insertion sort.
Analysis:
The insertion sort of linked list can be done in O(1) space. In this solution, I create a node, result, to contain the result. The result would be look like the following graph.
Sort a linked list in O(nlogn) time using constant space complexity.
When it comes to the algorithm that can sort in O(nlogn), it should be Merge sort, Quick sort, Heap sort. The difficult part in this question is the space complexity. If you choose recursive, the program stack will exceed the requirement and might lead to stack overflow. If you use Top-down merge sort, you will use another recursive in your program.
Basically, a recursive algorithm will add overhead since you store recursive calls in the execution stack.
But if the recursive function is the last line of the call (tail recursion) then there is no additional penalty.