LeetCode 1174: Immediate Food Delivery II Solution

Master LeetCode problem 1174 (Immediate Food Delivery II), a medium challenge, with our optimized solutions in Java, C++, and Python. Explore detailed explanations, test your code in our interactive editor, and prepare for coding interviews.

1174. Immediate Food Delivery II

Medium

Problem Explanation

Explanation:

To solve this problem, we need to calculate the percentage of immediate orders in the first orders of all customers. We can achieve this by first identifying the first order of each customer and then checking if it is an immediate order or not. Finally, we calculate the percentage of immediate first orders.

  1. Group the delivery records by customer_id.
  2. For each group, find the order with the earliest order_date as the first order.
  3. Check if the customer_pref_delivery_date of the first order is the same as the order_date (immediate order) or not.
  4. Calculate the percentage of immediate first orders.

:

Solution Code

# Write your Java solution here
SELECT ROUND(
    (SELECT COUNT(DISTINCT customer_id) 
    FROM Delivery 
    WHERE customer_id = (SELECT customer_id FROM Delivery ORDER BY order_date LIMIT 1) 
    AND order_date = customer_pref_delivery_date) * 100.0 / COUNT(DISTINCT customer_id), 2) AS immediate_percentage
FROM Delivery;

Try It Yourself

Loading code editor...

Related LeetCode Problems

Frequently Asked Questions

How to solve LeetCode 1174 (Immediate Food Delivery II)?

This page provides optimized solutions for LeetCode problem 1174 (Immediate Food Delivery II) in Java, C++, and Python, along with a detailed explanation and an interactive code editor to test your code.

What is the time complexity of LeetCode 1174 (Immediate Food Delivery II)?

The time complexity for LeetCode 1174 (Immediate Food Delivery II) varies by solution. Check the detailed explanation section for specific complexities in Java, C++, and Python implementations.

Can I run code for LeetCode 1174 on DevExCode?

Yes, DevExCode provides an interactive code editor where you can write, test, and run your code for LeetCode 1174 in Java, C++, or Python.

Back to LeetCode Solutions