iq.lab
Python starts when a code cell comes near or you run one
00 The interview and this lab

Checkpoint

The interview and this lab

Twelve questions across the three lessons, on inputs you have not seen. Trace every program by hand before you answer, the way you would in a round with no Run button. You pass at 80%.

  1. Question 1 of 12.

    A candidate tested this once: largest([7, 3, 5]) returned 7, which is right.

    def largest(nums):
        best = nums[0]
        for i in range(len(nums) - 1):
            if nums[i] > best:
                best = nums[i]
        return best

    Which one input exposes the bug?

  2. Question 2 of 12.

    You have five years of data engineering behind you, and a recruiter mentions a mid-level loop. Which statement fits the research?

  3. Question 3 of 12.

    Your set version of has_duplicate works. The interviewer asks: "Now the list arrives sorted, smallest first, like [1, 3, 3, 8]. Can you do it without the set?" Which answer names the follow-up type and answers it well?

  4. Question 4 of 12.

    This function is meant to return the smallest number in a list. Type exactly what the program prints, one value per line.

    def smallest(nums):
        low = 0
        for x in nums:
            if x < low:
                low = x
        return low
    
    print(smallest([-3, 5, -6]))
    print(smallest([4, 2, 9]))
    
  5. Question 5 of 12.

    This loop finds the coldest reading of a day:

    temps = [12, 9, 15, 7, 10]
    coldest = temps[0]
    for t in temps:
        if t < coldest:
            coldest = t

    Which sentence is the promise it keeps?

  6. Question 6 of 12.

    The pair version runs on [6, 2, 8, 2]. How many times does the line if nums[i] == nums[j]: run before the function returns True? Type a whole number.

    def has_duplicate(nums):
        for i in range(len(nums)):
            for j in range(i + 1, len(nums)):
                if nums[i] == nums[j]:
                    return True
        return False
    comparisons

    Type a number: 12, -1, 0.5 and 3/4 all work.

  7. Question 7 of 12.

    Someone swapped two lines of the set version. Type exactly what the program prints, one value per line.

    def has_duplicate(nums):
        seen = set()
        for x in nums:
            seen.add(x)
            if x in seen:
                return True
        return False
    
    print(has_duplicate([1, 2, 3]))
    print(has_duplicate([4, 4]))
    print(has_duplicate([]))
    
  8. Question 8 of 12.

    Run the tests before you submit. This question counts as correct if your latest run passes every check.

    Code itRecord days

    Daily order counts arrive as a list. A day sets a record when its count is strictly greater than every earlier day's count. The first day always sets one, since nothing came before it. Write count_records(orders), which returns how many days set a record.

    For [3, 5, 2, 8, 8, 9] the answer is 4: the 3, the 5, the first 8 and the 9. An empty list has no records.

    ⌘+Enter runsPython starts when a code cell comes near or you run one
    Write your code where the starter says raise NotImplementedError, then press Run tests. Each check says what it expects.
  9. Question 9 of 12.

    One problem's history: clean solves on days 0 and 1, the solution opened on day 4, then clean solves on days 5 and 6. The lab's ladder uses gaps of 1, 3, 7, 14 and 30 days, counted from the latest solve. On what day is the next re-solve due? Type the day number.

    day

    Type a number: 12, -1, 0.5 and 3/4 all work.

  10. Question 10 of 12.

    The prompt said: count the days with at least k orders. You wrote if x > k:, traced an example where no day had exactly k orders, and submitted. A hidden test with a day of exactly k orders failed. Which type of miss is this?

  11. Question 11 of 12.

    Eight minutes into a new medium problem, you are stuck. You have read the prompt three times and written nothing. What does the struggle cap say to do?

  12. Question 12 of 12.

    You have finished modules 3, 4 and 5 and solved each lesson's problems in a row. Your weekend block is free. Which session fits the research best?

0 of 12 answered. Unanswered questions count as wrong.