Question bank / Software Engineering, Coding, Intermediate
How to answer: Merge overlapping activity intervals and return the total active time.
Whether you sort first and keep the merging logic tidy.
What the interviewer is testing.
Sorting, interval invariants, complexity. Whether you sort first and keep the merging logic tidy.
An outline for this question.
- Sort the intervals by start time.
- Walk through them, keeping a current merged interval. If the next one overlaps, extend its end; if not, close it and start a new one.
- Add up the lengths of the merged intervals for the total active time.
- State O(n log n) for the sort and O(n) after it, and test touching intervals and one interval inside another.
The mistake to avoid.
Skipping the sort. Without it, overlaps that are far apart in the list are missed.
The general method: clarify, plan, code, test.
The same shape works for most coding questions, whatever the topic.
- Restate the problem and ask about inputs, size limits and edge cases before you write anything.
- Describe your approach and its complexity out loud, then check it makes sense with the interviewer.
- Write clean code in small steps, narrating as you go.
- Walk through a normal case and an edge case by hand, then say what you would test.
Practice it, out loud.
Reading an outline is not the same as saying it. Answer this question in a mock interview, in your own words, then compare it with the outline above.
More to practice.
Tell me about yourself and why this role is the right next step.
Software Engineering, Behavioral
Given a string, return the first non-repeating character and explain the complexity.
Software Engineering, Coding
Design an LRU cache with O(1) get and put operations.
Software Engineering, Coding
Design a notification service for email, SMS, and push at large scale.
Software Engineering, System Design
This is a Replysis practice question. It is not a leaked or official question from any company, and the outline is a guide to structure, not a script. Use your own experience and facts.