Kth Smallest Element in a Sorted Matrix
Kth Smallest Element in a Sorted MatrixGiven a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix. Note that it is the kth smal
Kth Smallest Element in a Sorted MatrixGiven a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix. Note that it is the kth smal
Longest Increasing SubsequenceGiven an unsorted array of integers, find the length of longest increasing subsequence. For example:Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence
Find the Duplicate NumberGiven an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is onl
H-Index IIFollow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm? Default:123func hIndex(citations []int) int {} 解答思路:建議可以先參考先前H-
Search a 2D Matrix IIWrite an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted in ascending from left to ri
Kth Smallest Element in a BSTGiven a binary search tree, write a function kthSmallest to find the kth smallest element in it. Note: You may assume k is always valid, 1 ? k ? BST’s total elements. Fol
Minimum Size Subarray SumGiven an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn’t one, return 0 instead. F
Two Sum II - Input array is sortedGiven an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function twoSum should
Find Peak ElementA peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ num[i+1], find a peak element and return its index. The array may contain multipl
Search in Rotated Sorted Array II Follow up for “Search in Rotated Sorted Array”: What if duplicates are allowed? Would this affect the run-time complexity? How and why? Suppose an array sorted in a
Search a 2D MatrixWrite an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted from left to right. The first i
Search Insert PositionGiven a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no dupl
Search for a RangeGiven an array of integers sorted in ascending order, find the starting and ending position of a given target value. Your algorithm’s runtime complexity must be in the order of O(lo
Search in Rotated Sorted ArraySuppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You are given a target v
Arranging CoinsYou have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins. Given n, find the total number of full staircase rows that can b
Valid Perfect SquareGiven a positive integer num, write a function which returns True if num is a perfect square else False. Note: Do not use any built-in library function such as sqrt. Example 1:12
Intersection of Two ArraysGiven two arrays, write a function to compute their intersection. ###For Example: 1Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2]. Note: Each element in the result
Intersection of Two Arrays IIGiven two arrays, write a function to compute their intersection. For Example:1Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2]. Note: Each element in the resul