Write an efficient algorithm that searches for a value in an
m x n matrix. If the target value is in the matrix, return
true; otherwise, return
For a given sorted array (ascending order) and a target number, find the first index of this number in
O(log n) time complexity. If the target number does not exist in the array, return
Reverse a linked list in-place and in one-pass.
Given a rotated sorted array, recover it to sorted array in-place. A rotated array is an array in which its elements are shifted. For example,
[3, 4, 1, 2] is a rotated array of array
[1, 2, 3, 4] by 2 places.
Given a non-overlapping interval list which is sorted by start point. Insert a new interval into it, make sure the list is still in order and non-overlapping (merge intervals if necessary).
Given an input string, reverse the string word by word.
Given an integers array
A of length
n, calculate array
B of length
B[i] is the product all elements of array
A[i]. In other words, let
p = A × ... × A[n - 1],
B[i] = p / A[i]. Do the computation without using the division operator.
Given an array of integers, find the subarray with smallest sum and return the sum. The subarray should contain at least one element from the array.
Given an array of integers, find the contiguous subarray with the largest sum and return the sum. The subarray should contain at least one element from the array.
Given an array of integers, the majority number is the number that occurs more than half of the size of the array. Find the number with O(n) time and O(1) space.