question_slug
stringlengths
3
77
title
stringlengths
1
183
slug
stringlengths
12
45
summary
stringlengths
1
160
⌀
author
stringlengths
2
30
certification
stringclasses
2 values
created_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
updated_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
hit_count
int64
0
10.6M
has_video
bool
2 classes
content
stringlengths
4
576k
upvotes
int64
0
11.5k
downvotes
int64
0
358
tags
stringlengths
2
193
comments
int64
0
2.56k
sales-analysis-iii
EASY PANDAS SOLLUTION, BEATS 99%
easy-pandas-sollution-beats-99-by-grzego-pvmg
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem seems to involve analyzing sales data and filtering it based on specific cr
grzegorzgatkowski
NORMAL
2023-08-24T05:55:19.024726+00:00
2023-08-24T05:55:19.024755+00:00
920
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem seems to involve analyzing sales data and filtering it based on specific criteria. We are given two DataFrames: one containing product information and another containing sales data. The goal appears to be to filter the sales d...
8
0
['Pandas']
4
sales-analysis-iii
MySQL, MS SQL and Oracle solution with explanations
mysql-ms-sql-and-oracle-solution-with-ex-u8m6
We may have 4 cases here:\n1) product has no any sales\n2) product sold in the spring of 2019 only\n3) product sold in other periods, but not in the spring of 2
vazhev
NORMAL
2022-04-23T22:48:01.734681+00:00
2022-04-23T22:48:01.734712+00:00
2,172
false
We may have 4 cases here:\n1) product has no any sales\n2) product sold in the spring of 2019 only\n3) product sold in other periods, but not in the spring of 2019\n4) product sold in the spring of 2019 and in other periods\n\nThe 2nd case only is correct for the task condition (**only sold in the spring of 2019, betwe...
8
0
['MySQL', 'Oracle', 'MS SQL Server']
4
sales-analysis-iii
Using Having, no sub query needed
using-having-no-sub-query-needed-by-jani-6aho
SELECT s.product_id, p.product_name\nFROM Sales s JOIN Product p\nON p.product_id = s.product_id\nGROUP BY s.product_id\nHAVING MIN(s.sale_date) >= \'2019-01-01
JaniceJ
NORMAL
2021-06-17T04:41:50.188563+00:00
2021-06-17T04:41:50.188610+00:00
772
false
SELECT s.product_id, p.product_name\nFROM Sales s JOIN Product p\nON p.product_id = s.product_id\nGROUP BY s.product_id\nHAVING MIN(s.sale_date) >= \'2019-01-01\' AND MAX(s.sale_date) <=\'2019-03-31 \'\n
8
0
[]
0
sales-analysis-iii
SQL Beginner: Simple Logic
sql-beginner-simple-logic-by-harshada202-0hu7
\tselect\n\t\ts.product_id, p.product_name\n\tfrom \n\t\tSales s join Product p\n\ton\n\t\ts.product_id = p.product_id\n\tgroup by\n\t\ts.product_id \n\thaving\
harshada2022
NORMAL
2022-09-19T17:30:37.318911+00:00
2022-09-19T17:30:37.318954+00:00
2,695
false
\tselect\n\t\ts.product_id, p.product_name\n\tfrom \n\t\tSales s join Product p\n\ton\n\t\ts.product_id = p.product_id\n\tgroup by\n\t\ts.product_id \n\thaving\n\t\tmin(s.sale_date) >= "2019-01-01" \n\t\tAND\n\t\tmax(s.sale_date) <= "2019-03-31"
7
0
['MySQL']
0
sales-analysis-iii
Easiest Mysql Solution
easiest-mysql-solution-by-sofiaisasavage-0h1r
select \nproduct_id, product_name\nfrom product\nwhere product_id not in\n(select product_id\nfrom sales\nwhere sale_date <\'2019-01-01\'or sale_date>\'2019-03-
sofiaisasavage
NORMAL
2020-05-31T17:33:58.710033+00:00
2020-05-31T17:33:58.710071+00:00
860
false
select \nproduct_id, product_name\nfrom product\nwhere product_id not in\n(select product_id\nfrom sales\nwhere sale_date <\'2019-01-01\'or sale_date>\'2019-03-31\')
7
1
[]
2
sales-analysis-iii
Beginner-Friendly Solution Using SQL Server || Clear
beginner-friendly-solution-using-sql-ser-vxxq
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
truongtamthanh2004
NORMAL
2024-06-01T08:57:52.449491+00:00
2024-06-01T08:57:52.449525+00:00
798
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
6
0
['MS SQL Server']
1
sales-analysis-iii
SIMPLE MSOLUTION WITH NOT EXISTS ( SQL SERVER + MYSQL )
simple-msolution-with-not-exists-sql-ser-j50d
Intuition\r\n Describe your first thoughts on how to solve this problem. \r\n\r\n# Approach\r\n Describe your approach to solving the problem. \r\n\r\n# Complex
cooking_Guy_9ice
NORMAL
2023-03-04T04:29:01.709762+00:00
2023-11-21T02:14:35.721661+00:00
695
false
# Intuition\r\n<!-- Describe your first thoughts on how to solve this problem. -->\r\n\r\n# Approach\r\n<!-- Describe your approach to solving the problem. -->\r\n\r\n# Complexity\r\n- Time complexity:\r\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\r\n\r\n- Space complexity:\r\n<!-- Add your space complexity ...
6
0
['MySQL', 'MS SQL Server']
1
sales-analysis-iii
Simplest solution using HAVING
simplest-solution-using-having-by-sukuma-vevo
\nSELECT Product.product_id, Product.product_name\nFROM Product \nINNER JOIN Sales \nON Product.product_id = Sales.product_id \nGROUP BY Sales.product_id \nHAVI
sukumar-satapathy
NORMAL
2022-09-21T19:35:41.938212+00:00
2023-01-30T10:30:15.669300+00:00
1,470
false
```\nSELECT Product.product_id, Product.product_name\nFROM Product \nINNER JOIN Sales \nON Product.product_id = Sales.product_id \nGROUP BY Sales.product_id \nHAVING MIN(Sales.sale_date) >= "2019-01-01" AND MAX(Sales.sale_date) <= "2019-03-31"\n```\nIf it helped or you learned a new way, kindly upvote. Thanks :)
6
0
['MySQL']
0
sales-analysis-iii
✅[Accepted] Solution for MySQL | Clean & Simple Code
accepted-solution-for-mysql-clean-simple-7fur
\nSELECT p.product_id, p.product_name\nFROM Product p JOIN Sales s ON p.product_id=s.product_id\nGROUP BY p.product_id\nHAVING MIN(s.sale_date) >= \'2019-01-01\
axitchandora
NORMAL
2022-05-24T17:57:28.029248+00:00
2022-05-24T17:57:28.029296+00:00
802
false
```\nSELECT p.product_id, p.product_name\nFROM Product p JOIN Sales s ON p.product_id=s.product_id\nGROUP BY p.product_id\nHAVING MIN(s.sale_date) >= \'2019-01-01\' \nAND MAX(s.sale_date) <= \'2019-03-31\';\n```
6
0
['MySQL']
0
sales-analysis-iii
simple solution
simple-solution-by-cindy1516-rmhx
\nselect a.product_id, product_name\nfrom Sales a\ninner join Product b\non a.product_id = b.product_id\ngroup by a.product_id\nhaving min(sale_date)>=\'2019-01
cindy1516
NORMAL
2019-06-17T07:20:52.599219+00:00
2019-06-17T07:20:52.599290+00:00
1,183
false
```\nselect a.product_id, product_name\nfrom Sales a\ninner join Product b\non a.product_id = b.product_id\ngroup by a.product_id\nhaving min(sale_date)>=\'2019-01-01\' and max(sale_date)<=\'2019-03-31\'\n;\n```
6
0
[]
0
sales-analysis-iii
My solution
my-solution-by-vnsemkin-re3z
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
vnsemkin
NORMAL
2024-10-05T12:18:04.976956+00:00
2024-10-05T12:18:04.976979+00:00
741
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
5
0
['PostgreSQL']
1
sales-analysis-iii
Easy to understand || SQL
easy-to-understand-sql-by-yashwardhan24_-h6fv
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
yashwardhan24_sharma
NORMAL
2023-03-09T06:02:43.227577+00:00
2023-03-09T06:02:43.227626+00:00
3,455
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
5
0
['Database', 'MySQL']
1
sales-analysis-iii
EASY MySQL Solution || LEFT JOIN || INNER JOINS
easy-mysql-solution-left-join-inner-join-l322
\n# Write your MySQL query statement below\nWITH rejected_ids AS (\n SELECT s.product_id\n FROM sales s\n WHERE s.sale_date NOT BETWEEN DATE(\'2019-01-
raghavdabra
NORMAL
2022-10-18T12:47:30.229295+00:00
2022-10-18T12:47:30.229337+00:00
4,216
false
```\n# Write your MySQL query statement below\nWITH rejected_ids AS (\n SELECT s.product_id\n FROM sales s\n WHERE s.sale_date NOT BETWEEN DATE(\'2019-01-01\') AND DATE(\'2019-03-31\')\n)\nSELECT DISTINCT p.product_id, p.product_name\nFROM product p\nINNER JOIN sales s ON s.product_id = p.product_id\nLEFT JOIN...
5
0
['MySQL']
2
sales-analysis-iii
My straight forward solution using [MySQL]MIN
my-straight-forward-solution-using-mysql-l9ru
\nSELECT P.PRODUCT_ID, P.PRODUCT_NAME\n FROM PRODUCT P\nJOIN SALES S\n USING (PRODUCT_ID)\nGROUP BY PRODUCT_ID\n HAVING MIN(S.SALE_DATE) >= \'2019-01-0
shivamleet07
NORMAL
2022-07-30T17:00:00.164905+00:00
2022-07-30T17:01:55.309300+00:00
1,305
false
```\nSELECT P.PRODUCT_ID, P.PRODUCT_NAME\n FROM PRODUCT P\nJOIN SALES S\n USING (PRODUCT_ID)\nGROUP BY PRODUCT_ID\n HAVING MIN(S.SALE_DATE) >= \'2019-01-01\' \n AND \n MAX(S.SALE_DATE) <= \'2019-03-31\'\n```
5
0
['MySQL']
0
sales-analysis-iii
Don't know the answer !
dont-know-the-answer-by-gogole-tsye
\n\n\n\nselect distinct p.product_id, product_name \nfrom product p left join \nsales s on p.product_id=s.product_id\ngroup by p.product_id\nhaving min(sale_dat
GOGOLE
NORMAL
2022-06-21T04:00:45.137968+00:00
2022-06-21T04:00:45.138005+00:00
386
false
![image](https://assets.leetcode.com/users/images/a3b1fb94-0a62-42f6-a1a9-0602786b8dce_1655784039.0457337.gif)\n\n\n```\nselect distinct p.product_id, product_name \nfrom product p left join \nsales s on p.product_id=s.product_id\ngroup by p.product_id\nhaving min(sale_date) >= \'2019-01-01\' \n and max(sale_date) <...
5
0
['MySQL']
0
sales-analysis-iii
MySQL 2 simple solutions with comment. (Runtime: 846ms, Faster than 99%)
mysql-2-simple-solutions-with-comment-ru-r1kv
Where and Select\nsql\nSELECT\n product_id,\n product_name\nFROM Product\n# get product where only sold in first quarter 2019\nWHERE product_id NOT IN (\n
NovaldiS
NORMAL
2022-05-20T16:58:28.066475+00:00
2022-05-20T16:58:28.066523+00:00
493
false
Where and Select\n```sql\nSELECT\n product_id,\n product_name\nFROM Product\n# get product where only sold in first quarter 2019\nWHERE product_id NOT IN (\n # get all product_id in table Sales Where not sold in first quarter 2019\n SELECT\n product_id\n FROM Sales\n WHERE sale_date < "2019-01-...
5
0
['MySQL']
2
sales-analysis-iii
Simple MySQL using HAVING SUM()=0
simple-mysql-using-having-sum0-by-joyele-dxvi
\nSELECT s.product_id,\nproduct_name\nFROM sales s\nJOIN product p\nON s.product_id=p.product_id\nGROUP BY s.product_id\nHAVING SUM(IF(sale_date BETWEEN \'2019-
joyelee2466
NORMAL
2019-12-19T02:55:09.381228+00:00
2020-04-28T08:55:18.369609+00:00
931
false
```\nSELECT s.product_id,\nproduct_name\nFROM sales s\nJOIN product p\nON s.product_id=p.product_id\nGROUP BY s.product_id\nHAVING SUM(IF(sale_date BETWEEN \'2019-01-01\' AND \'2019-03-31\',0,1))=0\n```
5
0
[]
5
sales-analysis-iii
Simple Solution using CTE
simple-solution-using-cte-by-shalinipm_4-20kw
IntuitionIntuition The goal is to identify products that were exclusively sold in the first quarter of 2019. The first step is to filter sales occurring within
Shalinipm_416
NORMAL
2025-01-03T06:53:57.387808+00:00
2025-01-03T06:53:57.387808+00:00
1,027
false
# Intuition Intuition The goal is to identify products that were exclusively sold in the first quarter of 2019. The first step is to filter sales occurring within this timeframe, and then exclude products with sales outside this range. The key insight is leveraging SQL constructs like WITH clauses (for Common Table Exp...
4
0
['MySQL']
2
sales-analysis-iii
Sales Analysis III | Pandas | Easy
sales-analysis-iii-pandas-easy-by-khosiy-ffbs
see the successfully Accepted Submission\n\nimport pandas as pd\n\ndef sales_analysis(product: pd.DataFrame, sales: pd.DataFrame) -> pd.DataFrame:\n # First,
Khosiyat
NORMAL
2023-09-19T18:31:19.949300+00:00
2023-10-01T17:38:52.098932+00:00
332
false
[see the successfully Accepted Submission](https://leetcode.com/submissions/detail/1053850673/)\n```\nimport pandas as pd\n\ndef sales_analysis(product: pd.DataFrame, sales: pd.DataFrame) -> pd.DataFrame:\n # First, we convert \'sale_date\' column to datetime if it\'s not already in datetime format\n sales[\'sale...
4
0
[]
2
sales-analysis-iii
Fast and efficient solution, step by step explanation.
fast-and-efficient-solution-step-by-step-zym6
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem requires finding the unique product IDs and names from the first quarter sa
andreypomortsev
NORMAL
2023-09-09T10:58:26.775813+00:00
2023-11-14T02:36:54.058857+00:00
588
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem requires finding the unique product IDs and names from the first quarter sales that are not present in the rest of the sales data.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nTo solve the problem of f...
4
0
['Database', 'Python', 'Python3', 'Pandas']
0
sales-analysis-iii
Solution with except
solution-with-except-by-alideveloper-6pcl
\n\n\nselect product_id, product_name from product where product_id in (\n select product_id from sales \n where sale_date between \'2019-01-01\' and \'20
alideveloper
NORMAL
2023-02-20T06:13:25.440272+00:00
2023-02-20T06:13:25.440315+00:00
588
false
\n\n\n**select product_id, product_name from product where product_id in (\n select product_id from sales \n where sale_date between \'2019-01-01\' and \'2019-03-31\'\n except \n select product_id from sales \n where sale_date not between \'2019-01-01\' and \'2019-03-31\'\n)**\n\n\n\n\n```
4
0
['MS SQL Server']
0
sales-analysis-iii
MySQL Solution
mysql-solution-by-abstractconnoisseurs-9bbd
Code\n\nSELECT s.product_id, product_name\nFROM Sales s\nLEFT JOIN Product p\nON s.product_id = p.product_id\nGROUP BY s.product_id\nHAVING MIN(sale_date) >= CA
abstractConnoisseurs
NORMAL
2023-01-27T09:10:02.444177+00:00
2023-01-27T09:10:02.444239+00:00
3,861
false
# Code\n```\nSELECT s.product_id, product_name\nFROM Sales s\nLEFT JOIN Product p\nON s.product_id = p.product_id\nGROUP BY s.product_id\nHAVING MIN(sale_date) >= CAST(\'2019-01-01\' AS DATE) AND\n MAX(sale_date) <= CAST(\'2019-03-31\' AS DATE)\n```
4
0
['Database', 'MySQL']
1
sales-analysis-iii
Faster than 98.73%, left join is faster than in
faster-than-9873-left-join-is-faster-tha-1qlq
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
allen43
NORMAL
2023-01-10T02:46:27.269052+00:00
2023-01-10T02:46:27.269082+00:00
3,357
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
4
0
['MS SQL Server']
0
sales-analysis-iii
Using INNER JOIN and GROUP BY
using-inner-join-and-group-by-by-shikhar-jd3i
SELECT \n p.product_id,\n p.product_name\n FROM Product p INNER JOIN Sales s\n ON p.product_id = s.product_id\n GROUP BY product_id\n HAVING M
shikharsaxena34
NORMAL
2022-07-18T17:46:35.605822+00:00
2022-07-18T17:46:35.605860+00:00
280
false
SELECT \n p.product_id,\n p.product_name\n FROM Product p INNER JOIN Sales s\n ON p.product_id = s.product_id\n GROUP BY product_id\n HAVING MIN(sale_date) >= \'2019-01-01\' AND MAX(sale_date) <= \'2019-03-31\';
4
0
['MySQL']
0
sales-analysis-iii
Simple sol with one Subquery
simple-sol-with-one-subquery-by-zakirh-yhou
\nSELECT DISTINCT p.product_id, product_name \nFROM Product p \nJOIN Sales s ON s.product_id = p.product_id \nWHERE s.sale_date BETWEEN \'2019-01-01\' AND \'201
zakirh
NORMAL
2022-07-08T17:24:19.211391+00:00
2022-07-11T12:24:43.599932+00:00
346
false
```\nSELECT DISTINCT p.product_id, product_name \nFROM Product p \nJOIN Sales s ON s.product_id = p.product_id \nWHERE s.sale_date BETWEEN \'2019-01-01\' AND \'2019-03-31\' \n AND p.product_id NOT IN (\n SELECT product_id \n FROM Sales \n ...
4
0
[]
3
sales-analysis-iii
Using INNER JOIN and GROUP BY
using-inner-join-and-group-by-by-suprati-2txi
\nSELECT s.product_id,p.product_name FROM Sales as s INNER JOIN Product as p ON s.product_id=p.product_id GROUP BY s.product_id HAVING MIN(sale_date)>=\'2019-01
supratim_code
NORMAL
2022-05-29T19:07:16.718617+00:00
2022-05-29T19:07:16.718656+00:00
310
false
```\nSELECT s.product_id,p.product_name FROM Sales as s INNER JOIN Product as p ON s.product_id=p.product_id GROUP BY s.product_id HAVING MIN(sale_date)>=\'2019-01-01\' AND MAX(sale_date)<=\'2019-03-31\';\n```
4
0
[]
0
sales-analysis-iii
Simple MSSQL Solution
simple-mssql-solution-by-codingkida-pfli
\nselect product_id, product_name\nfrom product \nwhere product_id not in(select product_id from sales where sale_date<\'2019-01-01\' or sale_date>\'2019-03-31\
codingkida
NORMAL
2022-04-06T00:38:58.775725+00:00
2022-04-06T00:38:58.775756+00:00
606
false
```\nselect product_id, product_name\nfrom product \nwhere product_id not in(select product_id from sales where sale_date<\'2019-01-01\' or sale_date>\'2019-03-31\')\n```
4
0
['MS SQL Server']
1
sales-analysis-iii
easy to understand my sql solution without join or cte
easy-to-understand-my-sql-solution-witho-96lk
easy my sql solution \n\nselect product_id, product_name from product where product_id not in ( \nselect product_id from sales\nwhere sale_date not between \'20
vasudha25
NORMAL
2022-02-22T19:21:26.646113+00:00
2022-02-22T19:21:26.646161+00:00
324
false
easy my sql solution \n```\nselect product_id, product_name from product where product_id not in ( \nselect product_id from sales\nwhere sale_date not between \'2019-01-01\' and \'2019-03-31\')\n```
4
0
[]
0
sales-analysis-iii
MySQL Min and Max Approach
mysql-min-and-max-approach-by-imranmahmo-bxwa
select p.product_id, p.product_name\nfrom product p\ninner join sales s on s.product_id = p.product_id\ngroup by p.product_id\nhaving min(sale_date) >= \'2019-0
imranmahmood-mba
NORMAL
2021-11-19T06:18:57.422666+00:00
2021-11-19T06:18:57.422700+00:00
283
false
select p.product_id, p.product_name\nfrom product p\ninner join sales s on s.product_id = p.product_id\ngroup by p.product_id\nhaving min(sale_date) >= \'2019-01-01\' and max(sale_date) <= \'2019-03-31\'
4
0
['MySQL']
0
sales-analysis-iii
Elegant Select Solution
elegant-select-solution-by-vishkk-bw98
\nSELECT \n\tproduct_id,\n\tproduct_name \nFROM\n\tProduct\nWHERE product_id NOT IN\n\t(SELECT\n\t\tproduct_id\n\tFROM \n\t\tSales\n\tWHERE\n\t\tsale_date \n
vishkk
NORMAL
2021-11-12T00:26:29.639511+00:00
2021-11-12T00:26:29.639556+00:00
317
false
```\nSELECT \n\tproduct_id,\n\tproduct_name \nFROM\n\tProduct\nWHERE product_id NOT IN\n\t(SELECT\n\t\tproduct_id\n\tFROM \n\t\tSales\n\tWHERE\n\t\tsale_date \n NOT BETWEEN \n \'2019-01-01\' AND \'2019-03-31\')\n```
4
0
[]
2
sales-analysis-iii
Faster than 100% of MS SQL Server online submissions
faster-than-100-of-ms-sql-server-online-8rmlu
\nSELECT p.product_id,\n p.product_name\nFROM product p\n JOIN sales s\n ON p.product_id = s.product_id\nGROUP BY p.product_id,\n
neudatageek
NORMAL
2021-03-08T22:12:29.519158+00:00
2021-03-08T22:12:29.519196+00:00
518
false
```\nSELECT p.product_id,\n p.product_name\nFROM product p\n JOIN sales s\n ON p.product_id = s.product_id\nGROUP BY p.product_id,\n p.product_name\nHAVING Min(sale_date) >= \'2019-01-01\'\n AND Max(sale_date) <= \'2019-03-31\' \n```
4
0
[]
0
sales-analysis-iii
✔️✔️✔️easy solution - MySQL || PostgreSQL || MS SQL Server⚡⚡⚡
easy-solution-mysql-postgresql-ms-sql-se-ekcp
Code - MySQL\n\nSELECT p.product_id, p.product_name\nFROM Product p\nLEFT JOIN Sales s\nON p.product_id = s.product_id\nGROUP BY s.product_id\nHAVING MIN(s.sale
anish_sule
NORMAL
2024-03-12T13:32:38.930189+00:00
2024-03-12T13:32:38.930223+00:00
361
false
# Code - MySQL\n```\nSELECT p.product_id, p.product_name\nFROM Product p\nLEFT JOIN Sales s\nON p.product_id = s.product_id\nGROUP BY s.product_id\nHAVING MIN(s.sale_date) > \'2018-12-31\' AND MAX(s.sale_date) < \'2019-04-01\'\n```\n\n# Code - MS SQL Server | PostgreSQL\n```\nSELECT p.product_id, p.product_name\nFROM P...
3
0
['MySQL', 'MS SQL Server']
2
sales-analysis-iii
MySQL Solution for Sales Analysis III Problem
mysql-solution-for-sales-analysis-iii-pr-7jq8
Intuition\n Describe your first thoughts on how to solve this problem. \nThe intuition behind the given solution is to select the product_id and product_name of
Aman_Raj_Sinha
NORMAL
2023-05-18T03:41:32.732464+00:00
2023-05-18T03:41:32.732508+00:00
1,718
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition behind the given solution is to select the product_id and product_name of products that had sales between a specific date range and had sales overall. The approach involves performing an inner join between the Sales table an...
3
0
['MySQL']
2
sales-analysis-iii
MySQL Solution
mysql-solution-by-pranto1209-vhdn
Code\n\n# Write your MySQL query statement below\nselect product_id, product_name from Product natural join Sales\ngroup by product_id \nhaving min(sale_date) >
pranto1209
NORMAL
2023-03-09T12:57:20.574851+00:00
2023-03-13T15:59:14.114032+00:00
2,324
false
# Code\n```\n# Write your MySQL query statement below\nselect product_id, product_name from Product natural join Sales\ngroup by product_id \nhaving min(sale_date) >= \'2019-01-01\' and max(sale_date) <= \'2019-03-31\'; \n```
3
0
['MySQL']
1
sales-analysis-iii
MYSQL Easy Solution ✅✅
mysql-easy-solution-by-shubhamjain287-jj5s
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
Shubhamjain287
NORMAL
2023-03-08T05:48:28.778930+00:00
2023-03-08T05:48:28.778988+00:00
4,538
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
3
0
['MySQL']
0
sales-analysis-iii
Simple Query || Sales Analysis III
simple-query-sales-analysis-iii-by-himsh-j3e6
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
himshrivas
NORMAL
2023-01-26T08:51:27.947706+00:00
2023-02-07T13:52:01.492919+00:00
3,213
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
3
0
['MySQL']
2
sales-analysis-iii
Simple Solution
simple-solution-by-mediocre-coder-kruk
\nSELECT\n DISTINCT p.product_id, p.product_name\nFROM\n Product p INNER JOIN Sales s ON p.product_id = s.product_id\nWHERE\n sale_date BETWEEN \'2019-
mediocre-coder
NORMAL
2022-09-19T19:14:36.166973+00:00
2022-09-19T19:14:36.167013+00:00
771
false
```\nSELECT\n DISTINCT p.product_id, p.product_name\nFROM\n Product p INNER JOIN Sales s ON p.product_id = s.product_id\nWHERE\n sale_date BETWEEN \'2019-01-01\' AND \'2019-03-31\' AND p.product_id NOT IN (\n SELECT\n p.product_id\n FROM\n Product p INNER JOIN Sales s ON p.p...
3
0
['Oracle']
1
sales-analysis-iii
Simple solution without joins
simple-solution-without-joins-by-ajinkya-d6gg
select product_id ,product_name\n from product \n where product_id not in (select product_id from sales where sale_date
ajinkyanhatolkar
NORMAL
2022-09-13T14:21:24.666191+00:00
2022-09-13T14:21:24.666241+00:00
662
false
select product_id ,product_name\n from product \n where product_id not in (select product_id from sales where sale_date not between \'2019-01-01\' AND \'2019-03-31\' ) and product_id in (select product_id from sales)\n
3
0
[]
2
sales-analysis-iii
Simple Solution
simple-solution-by-krex0r-krcz
sql\nSELECT Sales.product_id, Product.product_name\nFROM Sales\nLEFT JOIN Product\nUSING(product_id)\nGROUP BY product_id\nHAVING MIN(Sales.sale_date) >= \'2019
krex0r
NORMAL
2022-09-07T19:57:08.156512+00:00
2022-09-07T19:57:08.156549+00:00
499
false
```sql\nSELECT Sales.product_id, Product.product_name\nFROM Sales\nLEFT JOIN Product\nUSING(product_id)\nGROUP BY product_id\nHAVING MIN(Sales.sale_date) >= \'2019-01-01\'\nAND MAX(Sales.sale_date) <= \'2019-03-31\'\n```
3
0
['MySQL']
0
sales-analysis-iii
Faster than 93.61% | MySQL Easy Solution
faster-than-9361-mysql-easy-solution-by-iemof
```\nSELECT product_id, product_name\nFROM Product\nWHERE product_id IN (\n SELECT product_id FROM Sales\n GROUP BY product_id\n HAVING MIN(sale_date)
arghapaul002
NORMAL
2022-08-21T01:09:36.661173+00:00
2022-08-21T01:09:36.661210+00:00
742
false
```\nSELECT product_id, product_name\nFROM Product\nWHERE product_id IN (\n SELECT product_id FROM Sales\n GROUP BY product_id\n HAVING MIN(sale_date) >= \'2019-01-01\' AND MAX(sale_date) <= \'2019-03-31\');
3
0
['MySQL']
0
sales-analysis-iii
Easy to understand mySQL solution using a subquery
easy-to-understand-mysql-solution-using-yyzl2
\nSELECT product_id, product_name FROM product\n\nWHERE product_id IN \n\n\t(SELECT DISTINCT product_id FROM sales\n\n GROUP BY product_id \n\n HAVING M
atalayfa
NORMAL
2022-08-10T11:30:44.876000+00:00
2022-08-10T11:30:44.876050+00:00
623
false
```\nSELECT product_id, product_name FROM product\n\nWHERE product_id IN \n\n\t(SELECT DISTINCT product_id FROM sales\n\n GROUP BY product_id \n\n HAVING MIN(sale_date)>= \'2019-01-01\' \n AND MAX(sale_date) <= \'2019-03-31\')\n```
3
0
['MySQL']
1
sales-analysis-iii
✅ MySql, 2 solutions
mysql-2-solutions-by-ranbeer_singh-9bi5
\nselect p.product_id, p.product_name\nfrom Product p\nleft join Sales s\non p.product_id = s.product_id\ngroup by p.product_id\nhaving sum(s.sale_date between
Ranbeer_Singh
NORMAL
2022-07-16T02:39:41.762023+00:00
2022-07-16T02:39:41.762063+00:00
209
false
```\nselect p.product_id, p.product_name\nfrom Product p\nleft join Sales s\non p.product_id = s.product_id\ngroup by p.product_id\nhaving sum(s.sale_date between \'2019-01-01\' and \'2019-03-31\') = count(s.sale_date) \n\nOR\n\nselect p.product_id, p.product_name\nfrom Product p\ninner join Sales s on p.product_id = s...
3
0
['MySQL']
0
sales-analysis-iii
Faster than 95.27% of Oracle online submissions for Sales Analysis III
faster-than-9527-of-oracle-online-submis-9gqz
\nselect p.product_id\n ,p.product_name\nfrom product p\njoin (select s.product_id from sales s\n group by s.product_id\n having min(s.sale_dat
hoangdang
NORMAL
2022-07-13T13:45:13.359919+00:00
2022-07-13T13:45:13.359948+00:00
371
false
```\nselect p.product_id\n ,p.product_name\nfrom product p\njoin (select s.product_id from sales s\n group by s.product_id\n having min(s.sale_date) >= \'2019-01-01\'\n and max(s.sale_date) <= \'2019-03-31\') s1\non\np.product_id = s1.product_id\n```
3
0
['Oracle']
0
sales-analysis-iii
simple having solution
simple-having-solution-by-hardawaylong-9h4s
select product_id, product_name\nfrom Product\nwhere product_id in \n(select product_id\nfrom Sales\ngroup by product_id\nhaving max(sale_date) <= \'2019-03-31\
HardawayLong
NORMAL
2022-06-10T01:37:53.981901+00:00
2022-06-10T01:37:53.981925+00:00
241
false
select product_id, product_name\nfrom Product\nwhere product_id in \n(select product_id\nfrom Sales\ngroup by product_id\nhaving max(sale_date) <= \'2019-03-31\' and min(sale_date) >= \'2019-01-01\')
3
0
[]
0
sales-analysis-iii
Multiple ways of solving in MySQL
multiple-ways-of-solving-in-mysql-by-iam-k227
Approach 1(With CTE)\n\n\nWITH sell_history AS (\n SELECT\n s.product_id,\n SUM(CASE WHEN sale_date NOT BETWEEN \'2019-01-01\' AND \'2019-03-31
iamrafiul
NORMAL
2022-05-05T21:06:57.058085+00:00
2022-05-05T21:06:57.058126+00:00
331
false
**Approach 1(With CTE)**\n\n```\nWITH sell_history AS (\n SELECT\n s.product_id,\n SUM(CASE WHEN sale_date NOT BETWEEN \'2019-01-01\' AND \'2019-03-31\' THEN 1 ELSE 0 END) sold_outside,\n SUM(CASE WHEN sale_date BETWEEN \'2019-01-01\' AND \'2019-03-31\' THEN 1 ELSE 0 END) sold_inside\n FROM s...
3
0
['MySQL']
0
sales-analysis-iii
MYSQL very simple solution
mysql-very-simple-solution-by-sonicak-2d6h
\n# Write your MySQL query statement below\nselect p.product_id, p.product_name\nfrom product p\njoin sales s\non p.product_id=s.product_id\ngroup by s.product_
sonicak
NORMAL
2022-01-25T07:26:06.639993+00:00
2022-01-25T07:26:06.640024+00:00
330
false
```\n# Write your MySQL query statement below\nselect p.product_id, p.product_name\nfrom product p\njoin sales s\non p.product_id=s.product_id\ngroup by s.product_id\nhaving min(s.sale_date)>=\'2019-01-01\' and max(s.sale_date)<=\'2019-03-31\'\n```
3
0
[]
1
sales-analysis-iii
MYSQL
mysql-by-zizhengwang-ah40
```\nSELECT Product.product_id,product_name\nFROM Product\nINNER JOIN Sales USING(product_id)\nGROUP BY Product.product_id\nHAVING SUM(CASE WHEN\n sal
ZizhengWang
NORMAL
2021-02-01T04:01:46.868558+00:00
2021-02-01T04:01:46.868645+00:00
284
false
```\nSELECT Product.product_id,product_name\nFROM Product\nINNER JOIN Sales USING(product_id)\nGROUP BY Product.product_id\nHAVING SUM(CASE WHEN\n sale_date BETWEEN \'2019-01-01\' AND \'2019-03-31\' THEN 0\n ELSE 1\n END)=0;
3
0
[]
0
sales-analysis-iii
EASY MySQL solution
easy-mysql-solution-by-baixiaofanya123-ql42
\nSELECT sales.product_id, product_name\nFROM product\n JOIN sales ON product.product_id = sales.product_id\nGROUP BY product_id\nHAVING SUM(sale_date BETWEE
baixiaofanya123
NORMAL
2020-12-04T04:55:28.732339+00:00
2020-12-04T04:55:28.732382+00:00
318
false
```\nSELECT sales.product_id, product_name\nFROM product\n JOIN sales ON product.product_id = sales.product_id\nGROUP BY product_id\nHAVING SUM(sale_date BETWEEN \'2019-01-01\' AND \'2019-03-31\') = COUNT(sale_date)\n```\n
3
0
[]
0
sales-analysis-iii
Can someone please tell me what's wrong with this code?
can-someone-please-tell-me-whats-wrong-w-g77i
\nselect p.product_id,p.product_name from Product p join Sales s on p.product_id=s.product_id \nwhere s.sale_date between \'2019-01-01\' and \'2019-03-31\';\n\n
anshuman_05
NORMAL
2020-06-24T12:23:57.569343+00:00
2020-06-24T12:23:57.569375+00:00
227
false
```\nselect p.product_id,p.product_name from Product p join Sales s on p.product_id=s.product_id \nwhere s.sale_date between \'2019-01-01\' and \'2019-03-31\';\n```\n\n\n
3
0
[]
2
sales-analysis-iii
beats 80%
beats-80-by-shinymer-p9jy
\nselect temp.product_id, Product.product_name\nfrom (select product_id, \n sum(case when sale_date between \'2019-01-01\' and \'2019-03-31\' then 0 else
shinymer
NORMAL
2019-08-31T06:44:33.002999+00:00
2019-08-31T07:18:29.036564+00:00
415
false
```\nselect temp.product_id, Product.product_name\nfrom (select product_id, \n sum(case when sale_date between \'2019-01-01\' and \'2019-03-31\' then 0 else 1 end) as val\nfrom Sales\ngroup by product_id\nhaving val = 0) temp\njoin Product\non Product.product_id = temp.product_id\n```
3
0
[]
1
sales-analysis-iii
simple not in solution
simple-not-in-solution-by-akumammx-rsw0
select product_id,product_name from Product where product_id not in(select product_id from Sales where sale_date < \'2019-01-01\' or sale_date>\'2019-03-31\')
akumammx
NORMAL
2019-08-14T15:00:41.725359+00:00
2019-08-14T15:00:41.725390+00:00
360
false
select product_id,product_name from Product where product_id not in(select product_id from Sales where sale_date < \'2019-01-01\' or sale_date>\'2019-03-31\')
3
0
[]
1
sales-analysis-iii
Using First_value( ), MAX( ) and CTE
using-first_value-max-and-cte-by-amxnkz-en7s
IntuitionWhen the problem specified that the product_id should be sold only in the first quarter of 2019, my initial thought was to use the FIRST_VALUE() functi
amxnkz
NORMAL
2025-02-09T22:03:52.116300+00:00
2025-02-09T22:03:52.116300+00:00
457
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> When the problem specified that the product_id should be sold only in the first quarter of `2019`, my initial thought was to use the `FIRST_VALUE()` function along with `MAX()`. Although you could use `MIN()` instead, I chose to utilize `FI...
2
0
['MySQL']
0
sales-analysis-iii
👉🏻FAST AND EASY TO UNDERSTAND SOLUTION || MySQL
fast-and-easy-to-understand-solution-mys-7xpz
IntuitionApproachComplexity Time complexity: Space complexity: Code
djain7700
NORMAL
2025-01-08T18:11:02.028024+00:00
2025-01-08T18:11:02.028024+00:00
345
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
2
0
['Database', 'MySQL']
0
sales-analysis-iii
100% Beats✅✅Easiest MySQL Solution✅🔥💯Without Joins
100-beatseasiest-mysql-solutionwithout-j-hp4r
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
chinnibhargavi17
NORMAL
2024-11-12T02:34:23.434937+00:00
2024-11-12T02:34:23.434970+00:00
349
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
2
0
['MySQL']
0
sales-analysis-iii
PostgreSQL 92% solution
postgresql-92-solution-by-phiduyanh-ylcb
\n\n# Code\npostgresql []\n-- Write your PostgreSQL query statement below\nWITH cte AS\n( \n SELECT\n product_id,\n COUNT(sale_date) FILTER (WH
phiduyanh
NORMAL
2024-10-24T02:48:59.228098+00:00
2024-10-24T02:48:59.228128+00:00
161
false
\n\n# Code\n```postgresql []\n-- Write your PostgreSQL query statement below\nWITH cte AS\n( \n SELECT\n product_id,\n COUNT(sale_date) FILTER (WHERE sale_date BETWEEN \'2019-01-01\' AND \'2019-03-31\') AS first_quarter_sales,\n COUNT(sale_date) AS all_sales\n FROM Sales\n GROUP BY product...
2
0
['PostgreSQL']
0
sales-analysis-iii
Easiest Solution ~
easiest-solution-by-sheetaltondwalkar-krvh
Intuition\nWe need to report Product IDs exclusively sold in first quarter 2019. So if a product is sold in first quarter and also in later or prior then it sho
sheetaltondwalkar
NORMAL
2024-06-10T17:09:28.367299+00:00
2024-06-10T17:09:28.367340+00:00
623
false
# Intuition\nWe need to report Product IDs exclusively sold in first quarter 2019. So if a product is sold in first quarter and also in later or prior then it should not be reported.\n\n# Approach\nSince the output has product name, product id and sale date we join Product and Sales table. \nNext we check for 2 conditi...
2
0
['MySQL']
2
sales-analysis-iii
Easy Solution Using subquery
easy-solution-using-subquery-by-i_manish-zfnj
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
I_ManishSharma
NORMAL
2024-02-05T10:12:45.294635+00:00
2024-02-05T10:12:45.294664+00:00
1,037
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
2
0
['MySQL']
2
sales-analysis-iii
Beginner Friendly Solution | MySQL | No Joins
beginner-friendly-solution-mysql-no-join-yxki
\n\n# Code\n\nSELECT product_id, product_name\nFROM Product\nWHERE product_id IN (\n SELECT product_id\n FROM Sales\n GROUP BY product_id\n HAVING
Newbie_Nerd
NORMAL
2023-11-28T09:44:24.426675+00:00
2023-11-28T09:44:24.426702+00:00
977
false
\n\n# Code\n```\nSELECT product_id, product_name\nFROM Product\nWHERE product_id IN (\n SELECT product_id\n FROM Sales\n GROUP BY product_id\n HAVING MIN(sale_date) >= "2019-01-01" AND MAX(sale_date) <="2019-03-31"\n);\n\n```
2
0
['MySQL']
1
sales-analysis-iii
JOIN + LEFT JOIN
join-left-join-by-sergeyzhirkov-ju1m
\nSQL []\nSELECT p.product_id, p.product_name\nFROM product p\nJOIN sales s \n ON p.product_id = s.product_id AND s.sale_date between \'2019-01-01\' and \'2019
SergeyZhirkov
NORMAL
2023-10-24T02:51:25.850128+00:00
2024-09-22T19:14:41.754623+00:00
388
false
\n```SQL []\nSELECT p.product_id, p.product_name\nFROM product p\nJOIN sales s \n ON p.product_id = s.product_id AND s.sale_date between \'2019-01-01\' and \'2019-03-31\'\nLEFT JOIN sales s2\n ON p.product_id = s2.product_id AND s2.sale_date not between \'2019-01-01\' and \'2019-03-31\'\nWHERE s2.product_id is null\n...
2
0
['MySQL']
0
sales-analysis-iii
EASY TO UNDERSTAND, BEGINNER FRIENDLY 🔥
easy-to-understand-beginner-friendly-by-6dhop
EASY TO UNDERSTAND, BEGINNER FRIENDLY \uD83D\uDD25\n x your first thoughts on how to solve this problem. \n easy to understand \n\n# Code\n\n# Write your MySQL
Jaloldinov
NORMAL
2023-08-25T15:05:31.472300+00:00
2023-08-25T15:05:31.472323+00:00
755
false
# EASY TO UNDERSTAND, BEGINNER FRIENDLY \uD83D\uDD25\n<!-- x your first thoughts on how to solve this problem. -->\n easy to understand \n\n# Code\n```\n# Write your MySQL query statement below\nselect p.product_id, p.product_name \nfrom Product p\nWHERE p.product_id IN (SELECT s.product_id FROM Sales s \n WHE...
2
0
['MySQL']
2
sales-analysis-iii
where not between easy solution
where-not-between-easy-solution-by-jdu9a-n041
Intuition\nFast and clearly to understanf for beginners\n\n\n# Code\n\nSELECT product_id, product_name\nFROM product\nWHERE product_id IN (\n SELECT product_
jdu9a0009
NORMAL
2023-08-25T15:04:10.244072+00:00
2023-08-25T15:05:41.244798+00:00
293
false
# Intuition\nFast and clearly to understanf for beginners\n\n\n# Code\n```\nSELECT product_id, product_name\nFROM product\nWHERE product_id IN (\n SELECT product_id\n FROM sales\n WHERE sale_date BETWEEN \'2019-01-01\' AND \'2019-03-31\'\n) AND product_id NOT IN (\n SELECT product_id\n FROM sales\n ...
2
0
['MySQL']
2
sales-analysis-iii
Pandas solution
pandas-solution-by-teemacia-stnb
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
Teemacia
NORMAL
2023-08-19T10:29:12.412509+00:00
2023-08-19T10:29:12.412543+00:00
362
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
2
0
['Pandas']
1
sales-analysis-iii
Fast and simple query by MySQL!!!
fast-and-simple-query-by-mysql-by-nourim-r5ow
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
nourimanov
NORMAL
2023-06-02T11:57:36.655684+00:00
2023-06-02T11:57:36.655726+00:00
540
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
2
0
['MySQL']
0
sales-analysis-iii
👀🥷MySQL Solution
mysql-solution-by-dipesh_12-7nvm
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
dipesh_12
NORMAL
2023-04-14T15:40:58.143468+00:00
2023-04-14T15:40:58.143502+00:00
1,643
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
2
0
['MySQL']
1
sales-analysis-iii
MYSQL || MIN-MAX || HAVING
mysql-min-max-having-by-utkarshsakarwar-7kyh
\n\n# Code\n\n# Write your MySQL query statement below\nSELECT p.product_id,p.product_name\nFROM Product p\nLEFT JOIN Sales s\nON p.product_id=s.product_id\nGRO
utkarshsakarwar
NORMAL
2023-01-22T09:03:12.500780+00:00
2023-01-22T09:03:12.500814+00:00
648
false
\n\n# Code\n```\n# Write your MySQL query statement below\nSELECT p.product_id,p.product_name\nFROM Product p\nLEFT JOIN Sales s\nON p.product_id=s.product_id\nGROUP BY s.product_id\nHAVING MIN(s.sale_date)>\'2018-12-31\' AND MAX(s.sale_date)<\'2019-04-01\'\n```
2
0
['MySQL']
0
sales-analysis-iii
Solution for 1084. Sales Analysis III
solution-for-1084-sales-analysis-iii-by-e847l
Intuition\r\nObtain all the product id that were sold apart from requested dates.\r\noutput unique pid, pnames that are not in above result\r\n\r\n# Approach\r\
vigneshrajgopalnayak
NORMAL
2023-01-01T06:00:45.454717+00:00
2023-01-01T06:00:45.454761+00:00
932
false
# Intuition\r\nObtain all the product id that were sold apart from requested dates.\r\noutput unique pid, pnames that are not in above result\r\n\r\n# Approach\r\nUse temp table to join both sales and pproduct table\r\nInner join is needed.\r\n\r\n# Complexity\r\n- Time complexity:\r\n<!-- Add your time complexity here...
2
0
['MySQL']
0
sales-analysis-iii
MySQL || beats 100% || only with one select || inner join || easy-to-understand || best-solution
mysql-beats-100-only-with-one-select-inn-ncur
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
Muzaffar_khuja
NORMAL
2022-12-13T08:43:39.129279+00:00
2022-12-13T08:43:39.129316+00:00
931
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n100%\n\n- Space complexity:\n100%\n\n# Code\n```\nselect p.product_id, p.product_name from Product as p inner join Sales as s on \n...
2
0
['MySQL']
1
sales-analysis-iii
MySQL | Somple solution w/ DISTINCT
mysql-somple-solution-w-distinct-by-lulz-18tq
That\'s all:\n\nSELECT DISTINCT s.product_id, p.product_name\nFROM Product p\nLEFT JOIN Sales s ON p.product_id = s.product_id\nWHERE\n sale_date BETWEEN \'2
lulzseq
NORMAL
2022-09-11T17:33:24.141166+00:00
2022-09-11T17:33:24.141205+00:00
542
false
That\'s all:\n```\nSELECT DISTINCT s.product_id, p.product_name\nFROM Product p\nLEFT JOIN Sales s ON p.product_id = s.product_id\nWHERE\n sale_date BETWEEN \'2019-01-01\' AND \'2019-03-31\'\n AND s.product_id NOT IN (\n SELECT product_id\n FROM sales\n WHERE sale_date NOT BETWEEN \'2019-01-0...
2
0
['MySQL']
1
sales-analysis-iii
easy solution | sql
easy-solution-sql-by-rohan_fasale-tfv3
~~~\nselect product.product_id,product_name from product\njoin sales on product.product_id=sales.product_id\ngroup by product.product_id\nhaving max(sale_date)
Rohan_Fasale
NORMAL
2022-09-03T06:44:18.726107+00:00
2022-09-03T06:44:18.726135+00:00
226
false
~~~\nselect product.product_id,product_name from product\njoin sales on product.product_id=sales.product_id\ngroup by product.product_id\nhaving max(sale_date) <= "2019-03-31" and min(sale_date)>= "2019-01-01"\n~~~\n
2
0
[]
0
sales-analysis-iii
👇 MySQL 4 solutions | very easy 🔥 if | having | join
mysql-4-solutions-very-easy-if-having-jo-xa8b
\uD83D\uDE4B\uD83C\uDFFB\u200D\u2640\uFE0F Hello, here are my solutions to the problem.\n### Please upvote to motivate me post future solutions. HAPPY CODING \u
rusgurik
NORMAL
2022-08-28T04:05:52.768898+00:00
2022-08-28T04:05:52.768925+00:00
527
false
### \uD83D\uDE4B\uD83C\uDFFB\u200D\u2640\uFE0F Hello, here are my solutions to the problem.\n### Please upvote to motivate me post future solutions. HAPPY CODING \u2764\uFE0F\n##### Any suggestions and improvements are always welcome.\n##### Solution 1: If, join, long \uD83E\uDD26\uD83C\uDFFB\u200D\u2640\uFE0F\n##### \...
2
0
['MySQL']
2
sales-analysis-iii
Simple & Easy-to-Understand Solution
simple-easy-to-understand-solution-by-fr-wuc4
\'\'\'\n\n\n\tselect s.product_id, p.product_name\n\tfrom sales s, product p\n\twhere s.product_id = p.product_id\n\tgroup by s.product_id, p.product_name\n\tha
freezing_stone
NORMAL
2022-08-06T08:29:11.000356+00:00
2022-08-06T08:29:11.000382+00:00
208
false
\'\'\'\n\n\n\tselect s.product_id, p.product_name\n\tfrom sales s, product p\n\twhere s.product_id = p.product_id\n\tgroup by s.product_id, p.product_name\n\thaving min(s.sale_date) >= \'2019-01-01\' \n\t\tand max(s.sale_date) <= \'2019-03-31\'\n\'\'\'
2
0
['MySQL']
0
sales-analysis-iii
MySQL Solution
mysql-solution-by-raito_16_01_2001-cyz3
select distinct p1.product_id, p1.product_name\nfrom Product p1, Sales s1\nwhere p1.product_id not in(\n select product_id \n from Sales\n where sale_d
Raito_16_01_2001
NORMAL
2022-08-03T08:30:15.997981+00:00
2022-08-03T08:30:15.998015+00:00
235
false
select distinct p1.product_id, p1.product_name\nfrom Product p1, Sales s1\nwhere p1.product_id not in(\n select product_id \n from Sales\n where sale_date not between \'2019-01-01\' and \'2019-03-31\')\n and p1.product_id = s1.product_id
2
0
[]
0
sales-analysis-iii
✅✅ EXPLAINED MySQL || JOINS && HAVING && GROUP BY
explained-mysql-joins-having-group-by-by-fr6i
\n\n# So this command will give wrong answer because as there are duplicate\n#in the sales table therefore if you see in example acc. to this query , G4 will\n
bhomik23
NORMAL
2022-07-27T09:48:22.171181+00:00
2022-07-27T09:49:49.149886+00:00
216
false
```\n\n# So this command will give wrong answer because as there are duplicate\n#in the sales table therefore if you see in example acc. to this query , G4 will\n#also be printed because it has been bought in the spring but if you see it is \n#also been bought after the spring therefore we have to use group by so th...
2
0
[]
0
sales-analysis-iii
SQL for dummies! :)
sql-for-dummies-by-dennisdeneve-eoml
\tselect p.product_id, product_name \n\tfrom product p, sales s\n\twhere p.product_id = s.product_id\n\tgroup by p.product_id\n\thaving min(s.sale_date)>= \'201
dennisdeneve
NORMAL
2022-07-19T23:30:38.475826+00:00
2022-07-19T23:30:38.475858+00:00
165
false
\tselect p.product_id, product_name \n\tfrom product p, sales s\n\twhere p.product_id = s.product_id\n\tgroup by p.product_id\n\thaving min(s.sale_date)>= \'2019-01-01\' and max(s.sale_date) <= \'2019-03-31\';
2
0
[]
0
sales-analysis-iii
[MySQL] Easy solution with explanation in comment
mysql-easy-solution-with-explanation-in-1cy3j
\nSELECT\n product_id, product_name\nFROM\n Product\nWHERE\n\t# First, find out the product that were sold in 2019 Q1\n product_id IN (\n SELECT
kevin-shu
NORMAL
2022-07-07T07:02:00.068716+00:00
2022-07-10T16:52:20.147131+00:00
246
false
```\nSELECT\n product_id, product_name\nFROM\n Product\nWHERE\n\t# First, find out the product that were sold in 2019 Q1\n product_id IN (\n SELECT product_id\n FROM Sales\n WHERE\n sale_date BETWEEN \'2019-01-01\' AND \'2019-03-31\'\n )\n AND \n\t# Then, we have to elimin...
2
0
[]
1
sales-analysis-iii
MySQL solution, using MIN only
mysql-solution-using-min-only-by-evanfan-5yx6
\nselect s.product_id, p.product_name\nfrom Sales s\njoin Product p using (product_id)\ngroup by s.product_id having min(s.sale_date between \'2019-01-01\' and
evanfang
NORMAL
2022-07-06T10:58:53.266624+00:00
2022-07-06T10:58:53.266663+00:00
170
false
```\nselect s.product_id, p.product_name\nfrom Sales s\njoin Product p using (product_id)\ngroup by s.product_id having min(s.sale_date between \'2019-01-01\' and \'2019-03-31\') = 1\n```
2
0
[]
2
sales-analysis-iii
MySQL | Simple Approach
mysql-simple-approach-by-divine_a-2mlg
```\nSELECT s.product_id, product_name\nFROM Sales s LEFT JOIN Product p\nON s.product_id = p.product_id\nGROUP BY s.product_id\nHAVING MIN(sale_date) >= CAST(\
Divine_A
NORMAL
2022-07-02T10:25:57.105120+00:00
2022-07-02T10:25:57.105149+00:00
293
false
```\nSELECT s.product_id, product_name\nFROM Sales s LEFT JOIN Product p\nON s.product_id = p.product_id\nGROUP BY s.product_id\nHAVING MIN(sale_date) >= CAST(\'2019-01-01\' AS DATE) AND\nMAX(sale_date) <= CAST(\'2019-03-31\' AS DATE);
2
0
['MySQL']
0
sales-analysis-iii
My Simple SQL Solution
my-simple-sql-solution-by-user6774u-0d5j
\n\n\nSELECT\n p.product_id, p.product_name \nFROM \n Product p\nJOIN \n Sales s on p.product_id = s.product_id\nGROUP BY \n s.product_id\nHAVING \n
user6774u
NORMAL
2022-06-27T07:02:04.533307+00:00
2022-06-27T07:02:04.533340+00:00
289
false
\n```\n\nSELECT\n p.product_id, p.product_name \nFROM \n Product p\nJOIN \n Sales s on p.product_id = s.product_id\nGROUP BY \n s.product_id\nHAVING \n min(s.sale_date) >= \'2019-01-01\' \n and \n max(s.sale_date) <= \'2019-03-31\' \n; \n```\n\nPlease Upvote if you like the solution.\n
2
0
['MySQL']
0
sales-analysis-iii
MySQL solution faster than 97.93%
mysql-solution-faster-than-9793-by-darko-bpnm
\nSELECT \nDISTINCT # return just once if more than 1 is sold in requested time\nProduct.product_id, Product.product_name\nFROM\nProduct\nINNER JOIN\nSales\nON
darkoracic
NORMAL
2022-06-24T19:12:51.472559+00:00
2022-06-24T19:12:51.472604+00:00
253
false
```\nSELECT \nDISTINCT # return just once if more than 1 is sold in requested time\nProduct.product_id, Product.product_name\nFROM\nProduct\nINNER JOIN\nSales\nON Product.product_id = Sales.product_id\nWHERE\nSales.sale_date BETWEEN CAST(\'2019-01-01\' AS DATE) AND CAST(\'2019-03-31\' AS DATE) # sale has to be in reque...
2
0
['MySQL']
0
sales-analysis-iii
Mysql
mysql-by-ayush-sinha-gcp6
SELECT product_id,product_name FROM Product\nLEFT JOIN Sales USING(product_id)\nGROUP BY product_id\nHAVING MIN(sale_date) >= \'2019-01-01\'AND MAX(sale_date) <
Ayush-sinha
NORMAL
2022-06-16T07:03:40.470328+00:00
2022-06-16T07:03:40.470358+00:00
182
false
SELECT product_id,product_name FROM Product\nLEFT JOIN Sales USING(product_id)\nGROUP BY product_id\nHAVING MIN(sale_date) >= \'2019-01-01\'AND MAX(sale_date) < \'2019-04-01\'\n \n
2
0
[]
0
sales-analysis-iii
Two solution inspired by other solutions and as beginner
two-solution-inspired-by-other-solutions-z618
\n\n\n# 1St Method\nSELECT product_id, product_name \nFROM Product\nWHERE product_id NOT IN\n(\nSELECT product_id FROM Sales WHERE sale_date < "2019-01-01" OR s
pk80103
NORMAL
2022-06-07T03:39:55.804320+00:00
2022-06-07T03:39:55.804362+00:00
176
false
\n\n```\n# 1St Method\nSELECT product_id, product_name \nFROM Product\nWHERE product_id NOT IN\n(\nSELECT product_id FROM Sales WHERE sale_date < "2019-01-01" OR sale_date > "2019-03-31"\n);\n\n\n\n# 2nd Method using Group by\nSELECT Sales.product_id, Product.product_name \nFROM Sales \nJOIN Product \nON Product.produc...
2
0
[]
1
sales-analysis-iii
Sub Query and between
sub-query-and-between-by-aviskumar95-quim
select product_id,product_name from product\nwhere product_id not in\n(select product_id from sales\nwhere sale_date not between \'2019-01-01\' and \'2019-03-31
aviskumar95
NORMAL
2022-05-03T17:38:57.638489+00:00
2022-05-03T17:38:57.638517+00:00
233
false
select product_id,product_name from product\nwhere product_id not in\n(select product_id from sales\nwhere sale_date not between \'2019-01-01\' and \'2019-03-31\');
2
0
['MySQL']
0
exam-room
[C++/Java/Python] Straight Forward
cjavapython-straight-forward-by-lee215-l6wp
Very straight forward idea.\nUse a list L to record the index of seats where people sit.\n\nseat():\n 1. find the biggest distance at the start, at the end a
lee215
NORMAL
2018-06-17T03:12:49.176338+00:00
2018-10-24T00:13:02.450829+00:00
46,035
false
Very straight forward idea.\nUse a list `L` to record the index of seats where people sit.\n\n`seat()`:\n 1. find the biggest distance at the start, at the end and in the middle.\n 2. insert index of seat\n 3. return index\n\n`leave(p)`: pop out `p`\n\n\n**Time Complexity**:\nO(N) for `seat()` and `leave()`\n\...
202
31
[]
51
exam-room
[Python] O(log n) time for both seat() and leave() with heapq and dicts - Detailed explanation
python-olog-n-time-for-both-seat-and-lea-ytdo
We will name a range of unoccupied seats from i to j an Available segment with first index i and last index j. For each available segment we can say how far the
spatar
NORMAL
2018-06-17T06:24:42.995019+00:00
2018-10-23T12:35:31.767334+00:00
23,176
false
We will name a range of unoccupied seats from `i` to `j` an *Available segment* with first index `i` and last index `j`. For each available segment we can say how far the "best" seat in this segment is from the closest occupied seat. The number of empty seats in between is **priority** of the segment. The higher the pr...
175
1
[]
23
exam-room
Python heapq clean solution with explanation, seat O(log n) leave O(n)
python-heapq-clean-solution-with-explana-qng8
seat: O(log n)\nleave: O(n)\n\nThis solution is largely inspired by:\nhttps://leetcode.com/problems/exam-room/discuss/148595/Java-PriorityQueue-with-customized-
sfdye
NORMAL
2018-10-25T12:11:15.651001+00:00
2020-03-01T01:43:20.366959+00:00
9,899
false
seat: `O(log n)`\nleave: `O(n)`\n\nThis solution is largely inspired by:\nhttps://leetcode.com/problems/exam-room/discuss/148595/Java-PriorityQueue-with-customized-object.-seat:-O(logn)-leave-O(n)-with-explanation\n\nwith a few modification to work in Python. A few things I\'ve learned during the process:\n\n1. `heapq`...
142
0
[]
14
exam-room
C++ O(logn) seat() and O(logn) leave() with STL set and map
c-ologn-seat-and-ologn-leave-with-stl-se-5cm3
Much similar to the solution of @spatar, but my solution uses set rather than priority_queue to achieve exactly O(logn) seat() instead of potentially calling he
szp14
NORMAL
2018-06-23T11:45:15.579669+00:00
2018-10-25T10:33:41.589962+00:00
10,836
false
Much similar to the solution of [@spatar](https://leetcode.com/problems/exam-room/discuss/139941/Python-O(log-n)-time-for-both-seat()-and-leave()-with-heapq-and-dicts-Detailed-explanation), but my solution uses **set** rather than **priority_queue** to achieve exactly O(logn) seat() instead of potentially calling heapp...
101
0
[]
9
exam-room
[Java] Two TreeSets Solution. Both Seat and Leave O(log n) Time Complexity
java-two-treesets-solution-both-seat-and-b000
I was inspired by this solution. Please upvote his solution as well! Credit to @wangdeve.\n\nIn leave(seat) operation, we could take advantage of higher(seat) a
masonzhou
NORMAL
2019-10-14T03:27:00.337398+00:00
2019-10-14T05:23:21.601305+00:00
6,695
false
I was inspired by this [solution](https://leetcode.com/problems/exam-room/discuss/148595/Java-PriorityQueue-with-customized-object.-seat:-O(logn)-leave-O(n)-with-explanation). Please upvote his solution as well! Credit to [@wangdeve](https://leetcode.com/wangdeve "User").\n\nIn leave(seat) operation, we could take adva...
55
1
[]
9
exam-room
Java PriorityQueue Solution O(logN) for seat() O(N) for leave()
java-priorityqueue-solution-ologn-for-se-9n0f
seat(): Get the longest segment in pq, get the middle, update the pq\nleave(): Iterate the pq, get the two segments beside the p, update the pq\n\nSpent too muc
wangzi6147
NORMAL
2018-06-17T03:54:43.068599+00:00
2018-09-25T15:46:48.038678+00:00
11,971
false
`seat()`: Get the longest segment in `pq`, get the middle, update the `pq`\n`leave()`: Iterate the `pq`, get the two segments beside the `p`, update the `pq`\n\nSpent too much time dealing with the the edge cases. So sad.\n\n```\nclass ExamRoom {\n \n private PriorityQueue<int[]> pq;\n private int N;\n\n pu...
42
0
[]
10
exam-room
Java Solution based on treeset
java-solution-based-on-treeset-by-jainch-vct8
Idea is to Use a TreeSet to store the current seat index in use. Whenever we want to add a seat, check the max distance adjacent indices in the treeset, whichev
jainchethan87
NORMAL
2018-06-17T03:28:23.406946+00:00
2018-10-25T01:49:00.917487+00:00
6,310
false
Idea is to Use a [TreeSet](https://docs.oracle.com/javase/7/docs/api/java/util/TreeSet.html) to store the current seat index in use. Whenever we want to add a seat, check the max distance adjacent indices in the treeset, whichever is the max that is our answer.\nFor edge cases : \nWhen zero student: return 0;\nWhen the...
40
2
[]
2
exam-room
Easy to Understand Java Solution with Explanation - TreeSet
easy-to-understand-java-solution-with-ex-cbgw
What we really need in discussion section is a readable solution with detailed comments possible to make it look easier to understand, rather than just talking
rahul-raj
NORMAL
2021-07-11T16:21:52.972708+00:00
2021-07-11T16:21:52.972755+00:00
3,750
false
What we really need in discussion section is a readable solution with detailed comments possible to make it look easier to understand, rather than just talking about the same constraints already mentioned in the question! It is important to discuss the optimized solution, but it is also important to come up with a vi...
35
0
['Java']
6
exam-room
C++: Using ordered set
c-using-ordered-set-by-vmk1802-hp9v
Logic\n1. Ordered set is used to store occupied seats\n2. Distance between candidate seat and the nearest seat is calculated as below\n\t If end seats 0 or n-1
vmk1802
NORMAL
2021-05-09T09:47:54.929832+00:00
2021-07-06T16:41:14.150252+00:00
3,372
false
# Logic\n1. Ordered set is used to store occupied seats\n2. Distance between candidate seat and the nearest seat is calculated as below\n\t* If end seats 0 or n-1 are empty, the distance between the nearest seat is same as difference between occupied seat and the end candidate seat\n\t* For seats in between. the distan...
35
1
['C', 'Ordered Set', 'C++']
7
exam-room
My Elegant Java Solution Beats 99.84%
my-elegant-java-solution-beats-9984-by-s-qerh
Like other posts, the seat() is O(logn) and leave() is O(n). The pq only save Intervals that are available for later use.\n\nclass ExamRoom {\n class Interva
Shark-Chili
NORMAL
2018-11-14T01:34:31.715956+00:00
2018-11-14T01:34:31.715995+00:00
3,308
false
Like other posts, the `seat()` is O(logn) and `leave()` is O(n). The pq only save Intervals that are available for later use.\n```\nclass ExamRoom {\n class Interval {\n int start;\n int end;\n int length;\n public Interval(int start, int end) {\n this.start = start;\n ...
32
0
[]
4
exam-room
clean Java TreeSet solution
clean-java-treeset-solution-by-dictatorx-9n3n
\'\'\'\nclass ExamRoom {\n TreeSet set;\n int n;\n public ExamRoom(int N) {\n set = new TreeSet();\n n = N;\n }\n \n public int
dictatorx
NORMAL
2019-01-24T01:20:39.050095+00:00
2019-01-24T01:20:39.050159+00:00
1,695
false
\'\'\'\nclass ExamRoom {\n TreeSet<Integer> set;\n int n;\n public ExamRoom(int N) {\n set = new TreeSet();\n n = N;\n }\n \n public int seat() { \n if(set.size() == 0){\n set.add(0);\n return 0;\n } \n \n int gap = ...
21
0
[]
2
exam-room
Python - Intervals Based Problem - Max Heap ✅
python-intervals-based-problem-max-heap-t0bgu
I was not able to come up with an optimal solution myself. I had to look at the discussion section but I hardly found any solution that had a good explanation f
itsarvindhere
NORMAL
2023-10-22T16:53:50.507478+00:00
2023-10-22T17:01:21.564340+00:00
629
false
I was not able to come up with an optimal solution myself. I had to look at the discussion section but I hardly found any solution that had a good explanation for the Max Heap approach.\n\nSo, after spending almost 2 hours understanding the approach, I will try my best to explain what is going on here.\n\nSee, first, w...
18
0
['Heap (Priority Queue)', 'Python']
3
exam-room
Java TreeMap solution, O(logn) for each operation
java-treemap-solution-ologn-for-each-ope-at60
The major idea is to store intervals into the TreeMap, every time when we add a seat, we get the longest interval and put a seat in the middle, then break the i
laughingwithwallace
NORMAL
2018-06-17T04:32:43.056665+00:00
2018-10-08T15:54:29.866959+00:00
3,452
false
The major idea is to store intervals into the TreeMap, every time when we add a seat, we get the longest interval and put a seat in the middle, then break the interval into two parts. Notice that for intervals with odd length, we simply trim it into even length using len -= len & 1.\n```\nclass ExamRoom {\n\n TreeMa...
17
0
[]
3
exam-room
Python 3 || w/ comments
python-3-w-comments-by-spaulding-6ub2
\nclass ExamRoom:\n\n def __init__(self, n: int):\n self.n, self.room = n, []\n\n\n def seat(self) -> int:\n if not self.room: ans = 0
Spaulding_
NORMAL
2023-01-27T20:42:10.629615+00:00
2024-08-04T23:54:25.114449+00:00
2,632
false
```\nclass ExamRoom:\n\n def __init__(self, n: int):\n self.n, self.room = n, []\n\n\n def seat(self) -> int:\n if not self.room: ans = 0 # sit at 0 if empty room \n\n else:\n dist, prev, ans = self.room[0], self.room[0], 0 # set best between door and firs...
15
0
['Python3']
1
exam-room
C++ O(log N) for each operation, using BST(std::set) and hash table
c-olog-n-for-each-operation-using-bststd-1w0c
After inserted some students, the seats would be divided into many intervals.\nWe can sort these intervals, using a complex compare function.\nTo keep the sorte
zhoubowei
NORMAL
2018-06-19T17:51:26.293727+00:00
2018-10-08T03:59:53.545733+00:00
2,471
false
After inserted some students, the seats would be divided into many intervals.\nWe can sort these intervals, using a complex compare function.\nTo keep the sorted order after "insert" and "remove" operations, I use a BST to store these intervals.\n\nInsert operation:\n1. find the best interval (O(log n))\n2. get the mid...
15
0
[]
1
exam-room
[Python] O(log n) time for both seat() and leave() with a customized heap implementation
python-olog-n-time-for-both-seat-and-lea-6l3c
This solution is similar to https://leetcode.com/problems/exam-room/discuss/139941/Python-O(log-n)-time-for-both-seat()-and-leave()-with-heapq-and-dicts-Detaile
zhukov
NORMAL
2018-06-24T08:43:04.742604+00:00
2018-10-10T11:53:06.481473+00:00
2,147
false
This solution is similar to https://leetcode.com/problems/exam-room/discuss/139941/Python-O(log-n)-time-for-both-seat()-and-leave()-with-heapq-and-dicts-Detailed-explanation/147981. Many thanks to [@spatar](https://leetcode.com/spatar). \n\nThe main difference is that we will delete the segments from the heap when they...
12
0
[]
1
exam-room
Very simple C++ solution using set
very-simple-c-solution-using-set-by-pras-qh8v
\npublic:\n int last;\n set<int> s;\n ExamRoom(int n) {\n last = n-1;\n }\n \n int seat() {\n if(s.empty()){ //if the set is em
prashantarya10
NORMAL
2022-03-14T05:49:15.739499+00:00
2022-03-15T03:32:13.318876+00:00
1,235
false
```\npublic:\n int last;\n set<int> s;\n ExamRoom(int n) {\n last = n-1;\n }\n \n int seat() {\n if(s.empty()){ //if the set is empty, occupy the first seat\n s.insert(0);\n return 0;\n }\n \n //now we iterate over all the intervals\n //...
11
0
['C', 'Ordered Set']
0
exam-room
Python & Javascript // short and simple solution // similar to prob. no. 849
python-javascript-short-and-simple-solut-3oyv
Python\n\nclass ExamRoom:\n\n def __init__(self, N):\n self.seated, self.n = [], N - 1\n \n\n def seat(self):\n if not self.seated:\n
cenkay
NORMAL
2018-06-17T04:02:23.526392+00:00
2018-06-17T04:02:23.526392+00:00
1,324
false
* Python\n```\nclass ExamRoom:\n\n def __init__(self, N):\n self.seated, self.n = [], N - 1\n \n\n def seat(self):\n if not self.seated:\n self.seated += 0,\n return 0\n mx = ind = 0\n for i in range(1, len(self.seated)):\n l, r = self.seated[i -...
9
0
[]
0