Module challenge
Challenge: hash map
20 min · 3 steps
Step 1 of 3 · Write the code
solution(nums, target)Return the indexes
[i, j]of the two numbers innumsthat add up totarget, withi < j. You can't use the same number twice.Example:
solution([2, 7, 11, 15], 9)returns[0, 1].Constraints:
2 ≤ nums.length ≤ 10⁵-10⁹ ≤ nums[i], target ≤ 10⁹- Exactly one answer exists
function solution(nums, target) { }Step 2 of 3 · Write the code
solution(s)Return the index of the first letter in
sthat appears exactly once. If there isn't one, return-1.Example:
solution("loveleetcode")returns2(the letter "v").Constraints:
0 ≤ s.length ≤ 10⁵sonly contains lowercase letters
function solution(s) { }Step 3 of 3 · Write the code
solution(nums)Return the number that appears most often in
nums. On a tie, return the smallest of the tied numbers.Example:
solution([4, 1, 4, 1, 2])returns1(1 and 4 both appear twice, and 1 is smaller).Constraints:
1 ≤ nums.length ≤ 10⁵-10⁹ ≤ nums[i] ≤ 10⁹
function solution(nums) { }