← Live coding · Lesson 5 of 5

Testing, complexity and running out of time

Show you're careful: test edge cases, explain the complexity, and finish cleanly.

What they’re listening for

  • • Do you test your own code without being asked?
  • • Do you know the complexity, and why?
  • • Can you wrap up clearly when time is short?

Testing out loud

  1. You

    “Let me try a few cases. An empty list first, which should just give back an empty list. Then back-to-back meetings, which we said should merge. And one meeting inside another, which got me earlier.”

    print(merge_meetings([]))                   # []
    print(merge_meetings([(9, 10), (10, 11)]))  # [[9, 11]]
    print(merge_meetings([(9, 12), (10, 11)]))  # [[9, 12]]

    Say what each test checks and what you expect.

  2. You

    “Okay, all three look right.”

  3. Interviewer

    “Anything else you'd test?”

  4. You

    “Probably a single meeting, and two meetings with exactly the same times. I think both work, since the same start just merges, but I'd want to see them run.”

    “I think… but I'd want to see it run” is confident and careful at the same time.

Stiff vs. natural

Interviewer: “What's the time complexity?”

Sounds stiff

“The time complexity is big O of n log n. The space complexity is big O of n.”

Sounds natural

“So the sort is n log n, and after that we go through the list once, which is linear. The sort is the slow part, so it's n log n overall. Space is linear, for the merged list.”

  • Say where the number comes from, not just the number.
  • “n log n” and “linear” are how engineers say it out loud.

Interviewer: “We've got about five minutes left.”

Sounds stiff

“(types faster and says nothing)”

Sounds natural

“Okay, then I'll stop adding things here. To sum up: sort by start time, then one pass that merges as it goes. If I had ten more minutes, I'd check for bad input, like a meeting that ends before it starts, and turn these prints into real unit tests.”

  • Stop and sum up instead of rushing.
  • “If I had ten more minutes, I'd…” shows what you'd do next.

Testing and wrapping up

  • “Let me try a couple of cases.”Starting to test.
  • “Edge case: what if the list is empty?”Testing the boundaries.
  • “This is linear, since we only go through the list once.”Saying complexity naturally.
  • “The sort is the slow part, so it's n log n overall.”Explaining the overall cost.
  • “If I had ten more minutes, I'd…”When time is almost up.
  • “To sum up:”Recapping your solution in one or two sentences.

Now say it out loud

Rehearse with the AI interviewer and get feedback on your answers.