Skip to main content

Diagnostic check

About 15 minutes, five questions. Check each answer to see why every option is right or wrong. If you miss one, follow the review link before moving on. This is practice: nothing is recorded.

  1. Question 1 of 5What does CountAtLeast([4, 0, 12, 7], 5) return?

    Select one answer.

    Pseudocode
    PROCEDURE CountAtLeast(readings, threshold){  count ← 0  FOR EACH r IN readings  {    IF (r ≥ threshold)    {      count ← count + 1    }  }  RETURN count}
  2. Question 2 of 5This version uses > instead of ≥. What does it return for readings [5, 3, 5, 9] and threshold 5?

    Select one answer.

    Pseudocode
    PROCEDURE CountAtLeast(readings, threshold){  count ← 0  FOR EACH r IN readings  {    IF (r > threshold)    {      count ← count + 1    }  }  RETURN count}
  3. Question 3 of 5This version sets count to 0 inside the loop. What does it return for readings [8, 6, 9, 1] and threshold 5?

    Select one answer.

    Pseudocode
    PROCEDURE CountAtLeast(readings, threshold){  count ← 0  FOR EACH r IN readings  {    count ← 0    IF (r ≥ threshold)    {      count ← count + 1    }  }  RETURN count}
  4. Question 4 of 5Which two test cases give a different result for the > version than for the correct ≥ version? Choose two.

    Select exactly two answers (0 of 2 selected).

  5. Question 5 of 5What does FirstDayOver([2, 9, 4, 11], 5) return?

    Select one answer.

    Pseudocode
    PROCEDURE FirstDayOver(readings, threshold){  day ← 1  FOR EACH r IN readings  {    IF (r > threshold)    {      RETURN day    }    day ← day + 1  }  RETURN -1}

Your practice so far

Check an answer to see its rationale.