Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Fix Failing Tests in Codebase

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Fix Failing Tests in Codebase. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given an existing Python codebase with failing test cases, find the bug(s) and fix the code so the tests pass.

Asked in the Karat debugging round stage. The starter function is merge_intervals(intervals). It must return a new list of merged, non-overlapping intervals sorted by start value. Intervals that overlap or touch must be merged.

Signature: def merge_intervals(intervals):

Examples:

  • [[1, 3], [2, 6], [8, 10]] returns [[1, 6], [8, 10]] because the first two intervals overlap.
  • [[5, 7], [1, 3], [3, 5]] returns [[1, 7]] because touching intervals are merged.

Constraints: Each interval has two integers with start <= end; input length is at most 1,000; the input list must not be modified.

Constraints

  • 0 <= len(intervals) <= 1,000
  • Each interval contains exactly two integers
  • For every interval, start <= end
  • Intervals that touch, such as [1, 3] and [3, 5], must be merged
  • The input list and its interval lists must not be modified

Function Signature

def merge_intervals(intervals):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output