FastPrepGroup Timestamps into Consecutive-Day Intervals
Problems/Group Timestamps into Consecutive-Day Intervals

Group Timestamps into Consecutive-Day Intervals

Duolingo logoDuolingo● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Duolingo phone screen (full-time, experienced). Given an unsorted list of timestamps with a date, hour and minute, the task was to return the runs of consecutive days as date intervals, in linear time and without sorting. The interviewer allowed a date library, and any output order was fine.

The report does not give limits, examples, a range of years, or how each interval is written. Here, each interval is a start date and an end date, years run from 1900 to 2100, and there are up to 10^4 timestamps. Because any order was allowed, we fixed one: the intervals come in the order their first timestamp appears in the input.

Our version is about 85% the same as the reported question.

Given a list timestamps of times written as yyyy-mm-dd-hh-mm, in no particular order, return the intervals of consecutive active days. A day is active if at least one timestamp falls on it. Only the date part yyyy-mm-dd decides the day, and the hour and minute do not matter.

An interval is a longest run of consecutive calendar days that are all active. Write it as [startDate, endDate], with both dates in the form yyyy-mm-dd. A run of one day is [d, d]. Every active day belongs to exactly one interval.

Return the intervals in the order their first timestamp appears in timestamps: the interval holding the day of timestamps[0] comes first, then the interval of the first timestamp that is not in an interval listed so far, and so on.

Try to solve it in O(n) time without sorting, where n is the length of timestamps.

Note: days follow the Gregorian calendar. A year is a leap year when it is divisible by 4, except years divisible by 100 but not by 400. February has 29 days in a leap year and 28 days otherwise.

Function

activeDayIntervals(timestamps: List<String>) → List<List<String>>

Examples

Example 1

timestamps = ["2026-03-02-09-15","2026-02-27-23-59","2026-03-01-00-05","2026-02-28-12-00","2026-03-05-08-30"]return = [["2026-02-27","2026-03-02"],["2026-03-05","2026-03-05"]]

2026 is not a leap year, so March 1 comes right after February 28. The days February 27, February 28, March 1 and March 2 form one interval. March 5 stands alone. The first timestamp falls on March 2, so its interval comes first.

Example 2

timestamps = ["2024-02-29-10-00","2024-03-01-07-45","2023-12-31-22-10","2024-01-01-00-00","2024-02-29-18-30","2024-02-27-06-00"]return = [["2024-02-29","2024-03-01"],["2023-12-31","2024-01-01"],["2024-02-27","2024-02-27"]]

2024 is a leap year, so February 29 and March 1 are one interval, and February 27 is cut off from it because February 28 has no timestamp. December 31, 2023 and January 1, 2024 are also consecutive. The intervals are listed in the order their first timestamp appears: index 0, then 2, then 5.

Example 3

timestamps = ["2100-03-01-00-00","2100-02-28-23-59"]return = [["2100-02-28","2100-03-01"]]

2100 is divisible by 100 but not by 400, so it is not a leap year and March 1 follows February 28. Both days form one interval.

Constraints

  • 1 <= timestamps.length <= 10^4
  • Each timestamps[i] has the form yyyy-mm-dd-hh-mm and is a real date and time.
  • 1900 <= yyyy <= 2100, 00 <= hh <= 23 and 00 <= mm <= 59.
  • Timestamps may repeat, and many may fall on the same day.

More Duolingo Phone Screen questions

  • Return Every Matching DecryptionPHONE SCREEN · Seen Nov 2026
  • Visit Desired Attractions Without Reusing a TrailPHONE SCREEN · Seen Oct 2026
  • Correct an In-Place Array ReversalPHONE SCREEN · Seen Oct 2026
  • Count Starts Reaching a Grid MaximumPHONE SCREEN · Seen Oct 2026
  • Select the Top User MatchesPHONE SCREEN · Seen Oct 2026
  • Sum All Values in a Binary TreePHONE SCREEN · Seen Oct 2026
  • User Resource Transition ProbabilitiesPHONE SCREEN · Seen Oct 2026
  • Encrypt and Decrypt StringsPHONE SCREEN · Seen Apr 2026
  • Validate a Mahjong Hand PartitionPHONE SCREEN · Seen Nov 2025
  • Directional Tiles: Find a Valid Reconfiguration PathPHONE SCREEN · Seen Oct 2022

Similar questions at other companies

  • Shipping Cost Calculator Part 3 - Mixed Fixed/Incremental TiersStripe · PHONE SCREENStripe interview questions
  • Highlight and Rank Overlapping CitationsHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Route Pattern MatcherGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Classify Password StrengthHackerRank · PHONE SCREEN · ONSITE INTERVIEWHackerRank interview questions
  • Longest Substring Without Repeating CharactersAngel One · PHONE SCREEN
  • Group AnagramsWorkday · PHONE SCREEN
  • Video Cache Hit Rates from a CSV LogTubi · PHONE SCREEN
  • Longest Substring Without Repeating CharactersNykaa · PHONE SCREENNykaa interview questions
  • Apply Operations to Make a String EmptyFlexport · PHONE SCREENFlexport interview questions

Interview reports that mention this question

  • Duolingo interviews · November 2026

Duolingo interview experiences

  • Duolingo SWE Interview Questions: 3 Experiences
All Duolingo interview questionsSee Duolingo hiring insights
Saved
class Solution {
    public List<List<String>> activeDayIntervals(List<String> timestamps) {
        // Write your code here.
    }
}
Checking account…