Module challenge
Challenge: read the problem
15 min · 3 steps
Step 1 of 3 · Write the code
solution(nums, lo, hi)Return how many numbers in
numsare betweenloandhi, includingloandhi.Example:
solution([1, 5, 8, 10], 5, 9)returns2(the numbers 5 and 8).Constraints:
0 ≤ nums.length ≤ 1000-10⁶ ≤ nums[i], lo, hi ≤ 10⁶lo ≤ hi
function solution(nums, lo, hi) { }Step 2 of 3 · Write the code
solution(nums, target)Return the last index where
targetappears innums. If it doesn't appear, return-1.Example:
solution([4, 2, 4, 1], 4)returns2.Constraints:
0 ≤ nums.length ≤ 1000-1000 ≤ nums[i], target ≤ 1000
function solution(nums, target) { }Step 3 of 3 · Write the code
solution(nums)Return
trueifnumsis sorted in non-decreasing order (every number is greater than or equal to the one before it). Otherwise returnfalse.Example:
solution([1, 2, 2, 5])returnstrue.solution([3, 1])returnsfalse.Constraints:
0 ≤ nums.length ≤ 1000-10⁹ ≤ nums[i] ≤ 10⁹
function solution(nums) { }