Skip to the code
+10 XP

#34 Events per Calendar Day

easy

An activity feed groups events under date headers. Each event's time is a string like "2024-03-02 09:15" (year, month, day, then hours and minutes).

Write eventsPerDay(timestamps) that returns one [day, count] pair per day that has events, where day is the "YYYY-MM-DD" part. Sort the pairs by day, earliest first.

Example 1

Input: timestamps = ["2024-03-02 09:15","2024-03-01 18:00","2024-03-02 23:59"]
Output: [["2024-03-01",1],["2024-03-02",2]]

Two events fall on March 2 and one on March 1, and March 1 comes first.

Example 2

Input: timestamps = []
Output: []

No events, no days.

Constraints

  • 0 <= timestamps.length <= 10^5
  • Every timestamp has the form "YYYY-MM-DD HH:MM".
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).