Skip to content
Read the problem

Module challenge

Challenge: read the problem

15 min · 3 steps

  1. Step 1 of 3 · Write the code

    solution(nums, lo, hi)

    Return how many numbers in nums are between lo and hi, including lo and hi.

    Example: solution([1, 5, 8, 10], 5, 9) returns 2 (the numbers 5 and 8).

    Constraints:

    • 0 ≤ nums.length ≤ 1000
    • -10⁶ ≤ nums[i], lo, hi ≤ 10⁶
    • lo ≤ hi
    function solution(nums, lo, hi) { }
  2. Step 2 of 3 · Write the code

    solution(nums, target)

    Return the last index where target appears in nums. If it doesn't appear, return -1.

    Example: solution([4, 2, 4, 1], 4) returns 2.

    Constraints:

    • 0 ≤ nums.length ≤ 1000
    • -1000 ≤ nums[i], target ≤ 1000
    function solution(nums, target) { }
  3. Step 3 of 3 · Write the code

    solution(nums)

    Return true if nums is sorted in non-decreasing order (every number is greater than or equal to the one before it). Otherwise return false.

    Example: solution([1, 2, 2, 5]) returns true. solution([3, 1]) returns false.

    Constraints:

    • 0 ≤ nums.length ≤ 1000
    • -10⁹ ≤ nums[i] ≤ 10⁹
    function solution(nums) { }