Practice Restaurant Growth
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Tables: Customer(customer_id INT, name VARCHAR, visited_on DATE, amount INT). Customer has key (customer_id, visited_on). amount is that customer's payment for the day; at least one customer visits each day. For every complete seven-day window, return its ending visited_on, amount as the sum paid during the current date and preceding six dates, and average_amount as that sum divided by seven, rounded to two decimals. Aggregate all customers on a date before computing windows. Order by visited_on ascending.
Source: Restaurant Growth on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Customer table: +-------------+--------------+--------------+-------------+ | customer_id | name | visited_on | amount | +-------------+--------------+--------------+-------------+ | 1 | Jhon | 2019-01-01 | 100 | | 2 | Daniel | 2019-01-02 | 110 | | 3 | Jade | 2019-01-03 | 120 | | 4 | Khaled | 2019-01-04 | 130 | | 5 | Winston | 2019-01-05 | 110 | | 6 | Elvis | 2019-01-06 | 140 | | 7 | Anna | 2019-01-07 | 150 | | 8 | Maria | 2019-01-08 | 80 | | 9 | Jaze | 2019-01-09 | 110 | | 1 | Jhon | 2019-01-10 | 130 | | 3 | Jade | 2019-01-10 | 150 | +-------------+--------------+--------------+-------------+
+--------------+--------------+----------------+ | visited_on | amount | average_amount | +--------------+--------------+----------------+ | 2019-01-07 | 860 | 122.86 | | 2019-01-08 | 840 | 120 | | 2019-01-09 | 840 | 120 | | 2019-01-10 | 1000 | 142.86 | +--------------+--------------+----------------+
Related LeetCode Problems
Practice more problems similar to Restaurant Growth.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.