| Given a sorted integer array without duplicates, return the summary of its ranges. For example, given [0,1,2,4,5,7], return [“0->2”,“4->5”,“7”]. |
summary_ranges.cpp |
Given a 2D matrix, with following properties - Integers in each row are sorted in ascending from left to right.
- Integers in each column are sorted in ascending from top to bottom.
|
search2DII.cpp |
| Given an unsorted integer array, find the first missing positive integer.Example: [1,2,0] should return 3 and [3,4,-1,1] should return 2. Expected time complexity O(n) and solution should use constant space |
firstMissingPositiveNum.cpp |
| Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example: Given [100, 4, 200, 1, 3, 2]. The longest consecutive elements sequence is [1, 2, 3, 4]. Return its length: 4. Algorithm should run in O(n) complexity. |
longestConsecutiveSeq.cpp |
| Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2. The number of elements initialized in nums1 and nums2 are m and n respectively. |
mergeArrays.cpp |
Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Determine if you are able to reach the last index. For example: - A = [2,3,1,1,4], return true.
- A = [3,2,1,0,4], return false.
|
jumpGame.cpp |
| Given a positive integer, return its corresponding column title as appear in an Excel sheet. For example 1 -> A, 2 -> B,…26 -> Z, 27 -> AA, 28 -> AB, …705 -> AAC |
excelColSheetTitle.cpp |
| Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements. For example, given nums = [0, 1, 0, 3, 12], after calling your function, nums should be [1, 3, 12, 0, 0]. |
moveZeroes.cpp |
| Given an array of integers, find if the array contains any duplicates. Function should return true if any value appears at least twice in the array, and it should return false if every element is distinct. |
containsDuplicate.cpp |
Given a list, rotate the list to the right by k places, where k is non-negative. For example: - Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL
|
rotateList.cpp |
| 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:. |
editDistance.cpp |
| Given a binary tree, Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL. Initially, all next pointers are set to NULL.You may only use constant extra space.You may assume that it is a perfect binary tree (ie, all leaves are at the same level, and every parent has two children). |
connectNextPointers.cpp |
| Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is “((()))”, “(()())”, “(())()”, “()(())”, “()()()” |
generate_parenthesis.cpp |
| Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array.For example, Given nums = [0, 1, 3] return 2. |
missing_number.cpp |
| Suppose a sorted array 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). Find the minimum element. You may assume no duplicate exists in the array. |
find_min_rotated.cpp |
| Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution. |
threeSumClosest.cpp |
| Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water. Note: You may not slant the container. |
maxArea.cpp |
| Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the total sum of all root-to-leaf numbers. Example in solution comments |
sumRootToLeafNumbers.cpp |
| Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit. |
maxProfitStock.cpp |
| Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only move either down or right at any point in time. |
minPath.cpp |
| Count the number of prime numbers less than a non-negative number, n. |
countPrimes.cpp |
| Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers. Ensure that numbers within the set are sorted in ascending order. Example : for k = 3, n = 9 result would be [[1,2,6], [1,3,5], [2,3,4]], similarly for k = 3, n = 7, result would be [[1,2,4]]. |
combinationSum3.cpp |
| Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it. Follow up: Could you do it without any loop/recursion in O(1) runtime? |
addDigits.cpp |
| Given a matrix with cell values 0 or 1. Find the length of the shortest path from (a1, b1) to (a2, b2), such that path can only be constructed through cells which have value 1 and you can only travel in 4 possible directions, i.e. left, right, up and down. |
shortest_path_maze.cpp |
| The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calculate the Hamming distance. |
hamming_distance.cpp |
| Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. You need to merge them into a new binary tree. The merge rule is that if two nodes overlap, then sum node values up as the new value of the merged node. Otherwise, the NOT null node will be used as the node of new tree. |
merge_trees.cpp |
| Write a function that takes a string as input and reverse only the vowels of a string. |
reverse_vowels.cpp |
Given a string, sort it in decreasing order based on the frequency of characters.For example: - Input: cccbbbbaa Output: bbbcccaa
|
sortCharByFrequency.cpp |
| Product of Array Except Self. Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. |
product_except_self.cpp |
| Given a sorted array, remove duplicates in place and return the new length. It doesn’t matter what is in array beyond the unique elements size. Expected O(1) space and O(n) time complexity. |
remove_duplicates.cpp |
| Count the number of islands in a grid. Given a grid representing 1 as land body, and 0 as water body, determine the number of islands (more details in problem comments) |
count_islands.cpp |
| Find median from a data stream. Design a data structure that supports addNum to add a number to the stream, and findMedian to return the median of the current numbers seen so far. Also, if the count of numbers is even, return average of two middle elements, return median otherwise. |
median_stream.cpp |
| Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results. Note: The input string may contain letters other than the parentheses ( and ) |
remove_invalid_parenthesis.cpp |
| Given an array and a value, remove all instances of that value in-place and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. The order of elements can be changed. It doesn’t matter what you leave beyond the new length. |
remove_element.cpp |
| Find intersection of two arrays/vectors, Given two vectors find the result of their interaction. The result should only contain unique characters and can be in any order |
intersection_of_array.cpp |
| Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str. example: |
|
| pattern = “abba”, str = “dog cat cat dog” should return true. |
|
| pattern = “abba”, str = “dog cat cat fish” should return false. |
|
| pattern = “aaaa”, str = “dog cat cat dog” should return false. |
|
| pattern = “abba”, str = “dog dog dog dog” should return false. |
word_pattern.cpp |
| You are provided a vector of numbers, where each number represents |
|
| price of a stock on ith day. If you are permitted to only complete |
|
| one transaction per day (i.e buy one and sell one stock), design |
|
| an algorithm to find the maximum profit. |
best_time_to_buy_sell.cpp |
| Given a sentence, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. |
|
| Example: |
|
| Input: She loves chocolate |
|
| Output: ehs sevol etalocohc |
reverse_words.cpp |
评论