FastPrepMerge Weekday and Time Intervals
Problems/Merge Weekday and Time Intervals

Merge Weekday and Time Intervals

Nextdoor logoNextdoor● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Nextdoor phone screen for a full-time role. The original report is about merging intervals by weekday and time. It leaves open how to write them and what happens at the boundaries. Here we use single-week strings in one fixed form. Closed ranges are merged when they overlap or share an endpoint.

You are given an array of closed time intervals within one Monday-to-Sunday week. Each interval is written in this format: Day HH:MM -> Day HH:MM, where Day is one of Mon, Tue, Wed, Thu, Fri, Sat, or Sun, and each time uses 24-hour notation.

Merge every pair of intervals that overlaps or shares an endpoint. Return the merged intervals in ascending chronological order, using the same format.

All input intervals are valid, do not wrap past the end of Sunday, and have a start time no later than their end time. Intervals may arrive in any order.

Function

mergeWeeklyIntervals(intervals: String[]) → String[]

Examples

Example 1

intervals = ["Mon 09:00 -> Mon 12:00","Mon 12:00 -> Mon 17:00","Tue 10:00 -> Tue 11:00"]return = ["Mon 09:00 -> Mon 17:00","Tue 10:00 -> Tue 11:00"]

The two Monday intervals share the endpoint Mon 12:00, so they merge. The Tuesday interval remains separate.

Example 2

intervals = ["Wed 10:30 -> Thu 09:00","Tue 18:00 -> Wed 10:30","Fri 08:00 -> Fri 09:00"]return = ["Tue 18:00 -> Thu 09:00","Fri 08:00 -> Fri 09:00"]

After chronological sorting, the first two intervals touch at Wed 10:30 and become one cross-day interval.

Example 3

intervals = ["Sun 23:00 -> Sun 23:59","Mon 00:00 -> Mon 00:30","Mon 00:10 -> Mon 01:00"]return = ["Mon 00:00 -> Mon 01:00","Sun 23:00 -> Sun 23:59"]

The two Monday ranges overlap and merge. The Sunday range is later in the same week and remains separate.

Constraints

  • 1 <= intervals.length <= 100000
  • Every entry has the exact form Day HH:MM -> Day HH:MM.
  • Every time is between 00:00 and 23:59, inclusive.
  • Every interval stays within one Monday-to-Sunday week and has start <= end.

More Nextdoor Phone Screen questions

  • Build a File Tree from Streamed RecordsPHONE SCREEN · Seen Oct 2026
  • In-Memory Database with Transactions and SavepointsPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEWDuolingo interview questions
  • Group AnagramsWorkday · PHONE SCREEN
  • Group AnagramsEPAM · PHONE SCREENEPAM interview questions
  • Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
  • Find Duplicate File GroupsAnthropic · PHONE SCREENAnthropic interview questions
  • Largest NumberLinkedIn · PHONE SCREENLinkedIn interview questions
  • Insert an Employee into an Organization HierarchyWaymo · PHONE SCREENWaymo interview questions
  • Biggest Number From Gluing Numbers TogetherAdobe · PHONE SCREENAdobe interview questions
  • Group AnagramsMotive · PHONE SCREEN · ONSITE INTERVIEWMotive interview questions
  • Objects Seen on Both Days by Multiple ClientsGoogle · PHONE SCREENGoogle interview questions

Interview reports that mention this question

  • Nextdoor SWE Phone Screen Interview Experience: 1 Experience
All Nextdoor interview questionsSee Nextdoor hiring insights
Saved
class Solution {
    public String[] mergeWeeklyIntervals(String[] intervals) {
        // Write your code here.
    }
}
Checking account…