1174. Immediate Food Delivery II LeetCode Solution

In this guide, you will get 1174. Immediate Food Delivery II LeetCode Solution with the best time and space complexity. The solution to Immediate Food Delivery II 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

  1. Problem Statement
  2. Complexity Analysis
  3. Immediate Food Delivery II solution in C++
  4. Immediate Food Delivery II solution in Java
  5. Immediate Food Delivery II solution in Python
  6. Additional Resources
1174. Immediate Food Delivery II LeetCode Solution image

Problem Statement of Immediate Food Delivery II

Table: Delivery

+—————————–+———+
| Column Name | Type |
+—————————–+———+
| delivery_id | int |
| customer_id | int |
| order_date | date |
| customer_pref_delivery_date | date |
+—————————–+———+
delivery_id is the column of unique values of this table.
The table holds information about food delivery to customers that make orders at some date and specify a preferred delivery date (on the same order date or after it).

If the customer’s preferred delivery date is the same as the order date, then the order is called immediate; otherwise, it is called scheduled.
The first order of a customer is the order with the earliest order date that the customer made. It is guaranteed that a customer has precisely one first order.
Write a solution to find the percentage of immediate orders in the first orders of all customers, rounded to 2 decimal places.
The result format is in the following example.

Example not found

Constraints not found

Complexity Analysis

  • Time Complexity: Google AdSense
  • Space Complexity: Google Analytics

1174. Immediate Food Delivery II LeetCode Solution in C++

WITH
  CustomerToIsImmediate AS(
    SELECT
      DISTINCT customer_id,
      FIRST_VALUE(order_date = customer_pref_delivery_date) OVER(
        PARTITION BY customer_id
        ORDER BY order_date
      ) is_immediate
    FROM Delivery
  )
SELECT ROUND(AVG(is_immediate) * 100, 2) immediate_percentage
FROM CustomerToIsImmediate;
/* code provided by PROGIEZ */

1174. Immediate Food Delivery II LeetCode Solution in Java

N/A
// code provided by PROGIEZ

1174. Immediate Food Delivery II LeetCode Solution in Python

N/A
# code by PROGIEZ

Additional Resources

Happy Coding! Keep following PROGIEZ for more updates and solutions.