Skip to main content
Back to problems
Leetcode
Medium
Arrays
Strings
Hash Maps
Group Sold Products By the Date

Group sold product names by date and return, for each date, the distinct products sold and their counts.

Acceptance 0%
Problem Statement

You are given a list of sales records. Each record contains a date, a product name, and a quantity sold. For every date, aggregate the records so that each product appears once with the total number of units sold on that date.

Return the result organized by date in increasing order. For each date, list the products in lexicographic order, along with the summed quantity for that product.

Input Format

  • A collection of sales records.
  • Each record contains:
    • date: a string representing the sale date.
    • product: a string representing the product name.
    • quantity: a positive integer.

The exact input container may vary by language, but the logical structure is the same.

Output Format

Return a grouped structure ordered by date. For each date, include the product names sold on that date and the total quantity for each product.

Constraints

  • Dates can be compared as strings in chronological order when formatted consistently, such as YYYY-MM-DD.
  • Multiple records may exist for the same date and product.
  • Product names are case-sensitive unless stated otherwise.
  • The total quantity for a product on a date fits in a standard 32-bit signed integer.
Examples
Sample cases returned by the problem API.

Example 1

Input

records = [["2023-01-01","apple",3],["2023-01-01","banana",2],["2023-01-01","apple",1],["2023-01-02","banana",4]]

Output

[["2023-01-01",[["apple",4],["banana",2]]],["2023-01-02",[["banana",4]]]]

Explanation

On 2023-01-01, apple was sold twice, so its quantities are added: 3 + 1 = 4. The records are grouped by date, and products are listed once per date with their total counts.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.