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
8
Input: 

1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0

Output: 4

Readmore

85. Maximal Rectangle

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
8
Input:
[
["1","0","1","0","0"],
["1","0","1","1","1"],
["1","1","1","1","1"],
["1","0","0","1","0"]
]
Output: 6

Readmore

84. Largest Rectangle in Histogram

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.

Readmore

72. Edit Distance

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:

Readmore

companylist

——已推——

Walmart Sam’s Club Technology 8/14, 8/29 tech interview
https://goo.gl/BWxxLS

Readmore

LC24. Swap Nodes in Pairs

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.

Readmore

LC142. Linked List Cycle II

Reference:
https://en.wikipedia.org/wiki/Cycle_detection
https://leetcode.com/problems/linked-list-cycle-ii/solution/
https://goo.gl/SpP3Yb
https://goo.gl/UNFB98

Readmore

LC147. Insertion Sort List

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.

Readmore

LC148.Sort List

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.

Readmore

Space complexity between recursion and iterative

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.

Readmore