Given an array of strings, group anagrams together.
For example,
given: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”], Return:
1 2 3 4 5 |
|
Note:
All inputs will be in lower-case.
Given an array of strings, group anagrams together.
given: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”], Return:
1 2 3 4 5 |
|
All inputs will be in lower-case.
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)
You have the following 3 operations permitted on a word:
Implement int sqrt(int x).
Compute and return the square root of x.
There are two sorted arrays nums1 and nums2 of size m and n respectively.
Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).
nums1 = [1, 3] nums2 = [2]
The median is 2.0
nums1 = [1, 2] nums2 = [3, 4]
The median is (2 + 3)/2 = 2.5
Given a 2D binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area.
Given the following matrix:
1 2 3 4 |
|
Return 4.
Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix such that its sum is no larger than k.
1 2 3 4 5 |
|
The answer is 2. Because the sum of rectangle [[0, 1], [-2, 3]] is 2 and 2 is the max number no larger than k (k = 2).
The rectangle inside the matrix must have an area > 0. What if the number of rows is much larger than the number of columns?
Given two arrays, write a function to compute their intersection.
Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].
We are playing the Guess Game. The game is as follows:
I pick a number from 1 to n. You have to guess which number I picked.
Every time you guess wrong, I’ll tell you whether the number is higher or lower.
You call a pre-defined API guess(int num) which returns 3 possible results (-1, 1, or 0):
1 2 3 |
|
n = 10, I pick 6.
Return 6.
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.
Given preorder and inorder traversal of a tree, construct the binary tree.
Note: You may assume that duplicates do not exist in the tree.