1164. Product Price at a Given Date LeetCode Solution
In this guide, you will get 1164. Product Price at a Given Date LeetCode Solution with the best time and space complexity. The solution to Product Price at a Given Date problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.
Table of Contents
- Problem Statement
- Complexity Analysis
- Product Price at a Given Date solution in C++
- Product Price at a Given Date solution in Java
- Product Price at a Given Date solution in Python
- Additional Resources

Problem Statement of Product Price at a Given Date
Table: Products
+—————+———+
| Column Name | Type |
+—————+———+
| product_id | int |
| new_price | int |
| change_date | date |
+—————+———+
(product_id, change_date) is the primary key (combination of columns with unique values) of this table.
Each row of this table indicates that the price of some product was changed to a new price at some date.
Write a solution to find the prices of all products on 2019-08-16. Assume the price of all products before any change is 10.
Return the result table in any order.
The result format is in the following example.
Example not found
Constraints not found
Complexity Analysis
- Time Complexity: Google AdSense
- Space Complexity: Google Analytics
1164. Product Price at a Given Date LeetCode Solution in C++
WITH
RankedProducts AS (
SELECT
product_id,
new_price,
RANK() OVER(
PARTITION BY product_id
ORDER BY change_date DESC
) AS `rank`
FROM Products
WHERE change_date <= '2019-08-16'
),
ProductToLatestPrice AS (
SELECT product_id, new_price
FROM RankedProducts
WHERE `rank` = 1
)
SELECT
Products.product_id,
IFNULL(ProductToLatestPrice.new_price, 10) AS price
FROM Products
LEFT JOIN ProductToLatestPrice
USING (product_id)
GROUP BY 1;
/* code provided by PROGIEZ */
1164. Product Price at a Given Date LeetCode Solution in Java
N/A
// code provided by PROGIEZ
1164. Product Price at a Given Date LeetCode Solution in Python
N/A
# code by PROGIEZ
Additional Resources
- Explore all LeetCode problem solutions at Progiez here
- Explore all problems on LeetCode website here
Happy Coding! Keep following PROGIEZ for more updates and solutions.