You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: AmazonInterviewQuestionsByFrequency.md
+134Lines changed: 134 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2822,3 +2822,137 @@ public class Solution {
2822
2822
}
2823
2823
}
2824
2824
```
2825
+
2826
+
## [167. Two Sum II - Input array is sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/description/)
2827
+
2828
+
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.
2829
+
2830
+
The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are not zero-based.
2831
+
2832
+
You may assume that each input would have exactly one solution and you may not use the same element twice.
2833
+
```
2834
+
Input: numbers={2, 7, 11, 15}, target=9
2835
+
Output: index1=1, index2=2
2836
+
```
2837
+
2838
+
```java
2839
+
classSolution {
2840
+
publicint[] twoSum(int[] nums, inttarget) {
2841
+
int[] result =newint[]{0,0};
2842
+
for (int i =0, j = nums.length -1; i < j; ) {
2843
+
if (nums[i] + nums[j] == target) returnnewint[]{i+1, j+1};
2844
+
elseif (nums[i] + nums[j] > target) j--;
2845
+
else i++;
2846
+
}
2847
+
return result;
2848
+
}
2849
+
}
2850
+
```
2851
+
2852
+
## [692. Top K Frequent Words](https://leetcode.com/problems/top-k-frequent-words/description/)
2853
+
2854
+
Given a non-empty list of words, return the k most frequent elements.
2855
+
2856
+
Your answer should be sorted by frequency from highest to lowest. If two words have the same frequency, then the word with the lower alphabetical order comes first.
2857
+
2858
+
Example 1:
2859
+
```
2860
+
Input: ["i", "love", "leetcode", "i", "love", "coding"], k = 2
2861
+
Output: ["i", "love"]
2862
+
Explanation: "i" and "love" are the two most frequent words.
2863
+
Note that "i" comes before "love" due to a lower alphabetical order.
0 commit comments