3220. Odd and Even Transactions LeetCode Solution

In this guide, you will get 3220. Odd and Even Transactions LeetCode Solution with the best time and space complexity. The solution to Odd and Even Transactions 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. Odd and Even Transactions solution in C++
  4. Odd and Even Transactions solution in Java
  5. Odd and Even Transactions solution in Python
  6. Additional Resources
3220. Odd and Even Transactions LeetCode Solution image

Problem Statement of Odd and Even Transactions

Table: transactions

+——————+——+
| Column Name | Type |
+——————+——+
| transaction_id | int |
| amount | int |
| transaction_date | date |
+——————+——+
The transactions_id column uniquely identifies each row in this table.
Each row of this table contains the transaction id, amount and transaction date.

Write a solution to find the sum of amounts for odd and even transactions for each day. If there are no odd or even transactions for a specific date, display as 0.
Return the result table ordered by transaction_date in ascending order.
The result format is in the following example.

Example:

Input:
transactions table:

+—————-+——–+——————+
| transaction_id | amount | transaction_date |
+—————-+——–+——————+
| 1 | 150 | 2024-07-01 |
| 2 | 200 | 2024-07-01 |
| 3 | 75 | 2024-07-01 |
| 4 | 300 | 2024-07-02 |
| 5 | 50 | 2024-07-02 |
| 6 | 120 | 2024-07-03 |
+—————-+——–+——————+

Output:

+——————+———+———-+
| transaction_date | odd_sum | even_sum |
+——————+———+———-+
| 2024-07-01 | 75 | 350 |
| 2024-07-02 | 0 | 350 |
| 2024-07-03 | 0 | 120 |
+——————+———+———-+

Explanation:

For transaction dates:

2024-07-01:

Sum of amounts for odd transactions: 75
Sum of amounts for even transactions: 150 + 200 = 350

2024-07-02:

Sum of amounts for odd transactions: 0
Sum of amounts for even transactions: 300 + 50 = 350

See also  2410. Maximum Matching of Players With Trainers LeetCode Solution

2024-07-03:

Sum of amounts for odd transactions: 0
Sum of amounts for even transactions: 120

Note: The output table is ordered by transaction_date in ascending order.

Example not found

Constraints not found

Complexity Analysis

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

3220. Odd and Even Transactions LeetCode Solution in C++

SELECT
  transaction_date,
  SUM(IF(amount % 2 = 1, amount, 0)) AS odd_sum,
  SUM(IF(amount % 2 = 0, amount, 0)) AS even_sum
FROM Transactions
GROUP BY 1
ORDER BY 1;
/* code provided by PROGIEZ */

3220. Odd and Even Transactions LeetCode Solution in Java

N/A
// code provided by PROGIEZ

3220. Odd and Even Transactions LeetCode Solution in Python

N/A
# code by PROGIEZ

Additional Resources

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