Top Google Questions
1. Two Sum
3. Longest Substring Without Repeating Characters
4. Median of Two Sorted Arrays
5. Longest Palindromic Substring
6. ZigZag Conversion
8. String to Integer (atoi)
11. Container With Most Water
14. Longest Common Prefix
19. Remove Nth Node From End of List
23. Merge k Sorted Lists
24. Swap Nodes in Pairs
26. Remove Duplicates from Sorted Array
27. Remove Element
33. Search in Rotated Sorted Array
34. Find First and Last Position of Element in Sorted Array
35. Search Insert Position
38. Count and Say
41. First Missing Positive
46. Permutations
50. Pow(x, n)
51. N-Queens
53. Maximum Subarray
54. Spiral Matrix
55. Jump Game
59. Spiral Matrix II
60. Permutation Sequence
66. Plus One
67. Add Binary
69. Sqrt(x)
70. Climbing Stairs
72. Edit Distance
74. Search a 2D Matrix
75. Sort Colors
77. Combinations
,78. Subsets
79. Word Search
80. Remove Duplicates from Sorted Array II
81. Search in Rotated Sorted Array II
83. Remove Duplicates from Sorted List
84. Largest Rectangle in Histogram
88. Merge Sorted Array
94. Binary Tree Inorder Traversal
96. Unique Binary Search Trees
101. Symmetric Tree
102. Binary Tree Level Order Traversal
103. Binary Tree Zigzag Level Order Traversal
105. Construct Binary Tree from Preorder and Inorder Traversal
109. Convert Sorted List to Binary Search Tree
110. Balanced Binary Tree
114. Flatten Binary Tree to Linked List
118. Pascal's Triangle
119. Pascal's Triangle II
121. Best Time to Buy and Sell Stock
129. Sum Root to Leaf Numbers
130. Surrounded Regions
136. Single Number
137. Single Number II
144. Binary Tree Preorder Traversal
145. Binary Tree Postorder Traversal
146. LRU Cache
153. Find Minimum in Rotated Sorted Array
162. Find Peak Element
163. Missing Ranges
169. Majority Element
173. Binary Search Tree Iterator
174. Dungeon Game
198. House Robber
200. Number of Islands
205. Isomorphic Strings
207. Course Schedule
208. Implement Trie (Prefix Tree)
219. Contains Duplicate II
221. Maximal Square
222. Count Complete Tree Nodes
226. Invert Binary Tree
230. Kth Smallest Element in a BST
231. Power of Two
237. Delete Node in a Linked List
242. Valid Anagram
246. Strobogrammatic Number
, 1. Two Sum
Description
Given an array of integers, return indices of the two numbers such that they add
up to a specific target.
You may assume that each input would have exactly one solution, and you may not
use the same element twice.
Example:
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].
, Solution
01/02/2020:
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
unordered_map<int, int> m;
for (int i = 0; i < nums.size(); ++i) {
if (m.find(target - nums[i]) == m.end()) {
m[nums[i]] = i;
} else {
return {m[target - nums[i]], i};
}
}
return {-1, -1};
}
};
3. Longest Substring Without Repeating Characters
Description
Given a string, find the length of the longest substring without repeating
characters.
Example 1:
Input: "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.
Example 2:
Input: "bbbbb"
Output: 1
Explanation: The answer is "b", with the length of 1.
Example 3:
Input: "pwwkew"
Output: 3
Explanation: The answer is "wke", with the length of 3.
Note that the answer must be a substring, "pwke" is a subsequence
and not a substring.
Solution