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
customers-who-never-order
Share My first DB Answer
share-my-first-db-answer-by-siyang3-lfj1
I learn database from a Standford tutorial.\n\nhttps://www.youtube.com/watch?v=D-k-h0GuFmE&list=PL6hGtHedy2Z4EkgY76QOcueU8lAC4o6c3\n\n select Name as Custom
siyang3
NORMAL
2015-02-25T22:49:28+00:00
2015-02-25T22:49:28+00:00
1,934
false
I learn database from a Standford tutorial.\n\nhttps://www.youtube.com/watch?v=D-k-h0GuFmE&list=PL6hGtHedy2Z4EkgY76QOcueU8lAC4o6c3\n\n select Name as Customers\n from Customers\n where Id not in\n (select CustomerId as Id from Orders);
6
0
[]
1
customers-who-never-order
Pandas | SQL | EASY | Customers Who Never Order | Easy Explained
pandas-sql-easy-customers-who-never-orde-giyn
First Approach\nSee the Accepted and Successful Submission Detail\n\n\ndef find_customers(customers: pd.DataFrame, orders: pd.DataFrame) -> pd.DataFrame:\n \
Khosiyat
NORMAL
2023-09-17T10:58:43.161944+00:00
2023-10-01T17:32:47.159956+00:00
534
false
First Approach\n[See the Accepted and Successful Submission Detail](https://leetcode.com/submissions/detail/1051717047/)\n\n```\ndef find_customers(customers: pd.DataFrame, orders: pd.DataFrame) -> pd.DataFrame:\n \n # Perform a left join between \'Customers\' and \'Orders\'\n merged = customers.merge(orders, ...
5
0
['MySQL']
2
customers-who-never-order
Simple Python Pandas Solution ✅✅
simple-python-pandas-solution-by-lil_toe-cwcn
Code\n\nimport pandas as pd\n\ndef find_customers(customers: pd.DataFrame, orders: pd.DataFrame) -> pd.DataFrame:\n never_o=pd.DataFrame()\n never_o[\'Cus
Lil_ToeTurtle
NORMAL
2023-08-16T09:07:11.057012+00:00
2023-08-16T09:07:11.057044+00:00
942
false
# Code\n```\nimport pandas as pd\n\ndef find_customers(customers: pd.DataFrame, orders: pd.DataFrame) -> pd.DataFrame:\n never_o=pd.DataFrame()\n never_o[\'Customers\']=customers[~customers.id.isin(orders.customerId)][\'name\']\n return never_o\n```
5
0
['Pandas']
2
customers-who-never-order
MySQL Solution
mysql-solution-by-pranto1209-81qt
Code\n\n# Write your MySQL query statement below\nselect name as \'Customers\' from Customers\nwhere id not in (select customerid from Orders);\n
pranto1209
NORMAL
2023-01-12T22:23:46.480884+00:00
2023-03-13T16:06:36.427522+00:00
2,571
false
# Code\n```\n# Write your MySQL query statement below\nselect name as \'Customers\' from Customers\nwhere id not in (select customerid from Orders);\n```
5
0
['MySQL']
2
customers-who-never-order
Customers that dont order
customers-that-dont-order-by-niharika_so-js76
Intuition\nRequires Join\n\n# Approach\nFigure out which join is to be used and then where condition\n\n# Complexity\n- Time complexity:\nBegginer\n\n- Space co
niharika_solanki
NORMAL
2022-10-21T10:14:46.403884+00:00
2022-10-21T10:14:46.403918+00:00
1,231
false
# Intuition\nRequires Join\n\n# Approach\nFigure out which join is to be used and then where condition\n\n# Complexity\n- Time complexity:\nBegginer\n\n- Space complexity:\n4 lines\n\n# Code\n```\n/* Write your T-SQL query statement below */\nselect customers.name as Customers from customers\nleft join orders\non custo...
5
0
['MS SQL Server']
0
customers-who-never-order
3 Simple Solutions (1. NOT IN, 2. NOT EXISTS, 3. LEFT JOIN)
3-simple-solutions-1-not-in-2-not-exists-ecvq
1. Using NOT IN\nselect name as Customers from customers c\nwhere c.id not in (select customerId from orders)\n\n2. Using NOT EXISTS\nselect name as Customers f
Einsatz
NORMAL
2022-07-14T15:12:21.323933+00:00
2022-07-14T15:12:21.323970+00:00
344
false
**1. Using NOT IN**\nselect name as Customers from customers c\nwhere c.id not in (select customerId from orders)\n\n**2. Using NOT EXISTS**\nselect name as Customers from customers c\nwhere not exists (select 1 from orders o where c.id = o.customerId)\n\n**3. LEFT JOIN**\nselect name as Customers from customers c\nlef...
5
0
['MySQL']
0
customers-who-never-order
Two Simple Solutions - Nested Query & Left Join
two-simple-solutions-nested-query-left-j-igg1
\n#Nested Query:\nSELECT name AS Customers FROM Customers \nWHERE id NOT IN ( SELECT customerId FROM orders );\n\n\n\n# Left Join\nSELECT c.name AS Customers \n
pruthashouche
NORMAL
2022-07-02T23:35:51.816161+00:00
2022-07-02T23:35:51.816207+00:00
285
false
```\n#Nested Query:\nSELECT name AS Customers FROM Customers \nWHERE id NOT IN ( SELECT customerId FROM orders );\n```\n\n```\n# Left Join\nSELECT c.name AS Customers \nFROM Customers c LEFT JOIN Orders o\nON c.id=o.CustomerId\nWHERE o.id is NULL;\n```\n\n**Please UpVote if it was Helpful :)**
5
0
['MySQL']
1
customers-who-never-order
Customers Who Never Order
customers-who-never-order-by-coolsand172-4a6q
\nSELECT\n name as Customers\nFROM \n Customers\nwhere \n id NOT IN (SELECT customerId FROM Orders);\n\nUpvote IF IT Help
coolsand1727
NORMAL
2022-06-21T09:25:34.443233+00:00
2022-06-21T09:25:34.443268+00:00
436
false
```\nSELECT\n name as Customers\nFROM \n Customers\nwhere \n id NOT IN (SELECT customerId FROM Orders);\n```\nUpvote IF IT Help
5
0
['MySQL']
1
customers-who-never-order
MYSQL Using || not in ||
mysql-using-not-in-by-smilyface_123-4tkq
\nselect c1.name as Customers \n from Customers c1\n Where c1.id not in ( select O.customerId \n from Orders O );\n\t\t\t\t\t \
smilyface_123
NORMAL
2022-04-20T17:35:44.866809+00:00
2022-04-20T17:35:44.866851+00:00
438
false
```\nselect c1.name as Customers \n from Customers c1\n Where c1.id not in ( select O.customerId \n from Orders O );\n\t\t\t\t\t \n\t\tIF Helpful Please Like And Upvoke\t\t\t \n```
5
0
['MS SQL Server']
0
customers-who-never-order
best easiest simplest mysql using subquery - 183. Customers Who Never Order
best-easiest-simplest-mysql-using-subque-olp2
\nselect name as Customers from customers where id NOT IN \n(select customerId from Orders);\n\n\n#pls upvote if you find solution easy to understand..Thanks..!
divyagoel1
NORMAL
2022-02-27T11:38:16.326508+00:00
2022-02-27T11:38:16.326550+00:00
294
false
```\nselect name as Customers from customers where id NOT IN \n(select customerId from Orders);\n\n\n#pls upvote if you find solution easy to understand..Thanks..!!\n```
5
0
['MySQL']
0
customers-who-never-order
Several ways to solve this type of questions - IN A NOT IN B
several-ways-to-solve-this-type-of-quest-fgxy
Genrally this type of questions contain more than one table (sometimes one table but comparing among fields), and the goal is to find records in table A but not
lisayang0620
NORMAL
2021-04-27T16:03:54.192254+00:00
2021-05-25T14:19:08.841110+00:00
355
false
Genrally this type of questions contain more than one table (sometimes one table but comparing among fields), and the goal is to find records in table A but not in table B. More complicated questions are looking for records in table A but not in table B with certian critera (e.g. range of time, overlaps, flags, distinc...
5
0
[]
0
customers-who-never-order
Easy and Simple Three Solutions 🚀 | Beginner-Friendly 🎓 | Beats 94.72% ⚡
easy-and-simple-three-solutions-beginner-4nnf
🎯Approach 1 Using NOT IN 🔍🖥️Code🧠Time Complexity Analysis The subquery (SELECT customerId FROM Orders) runs in O(M). The outer query (SELECT FROM Customers WHER
bulbul_rahman
NORMAL
2025-03-16T18:13:58.506841+00:00
2025-03-16T18:13:58.506841+00:00
812
false
# 🎯Approach 1 Using NOT IN 🔍 # 🖥️Code ```mysql [] select name AS Customers FROM Customers WHERE Id Not In ( SELECT customerId FROM Orders ) ``` # 🧠Time Complexity Analysis - **The subquery** (SELECT customerId FROM Orders) runs in **O(M)**. - **The outer query** (SELECT FROM Custo...
4
0
['MS SQL Server']
2
customers-who-never-order
✅Beats 64.11% 🔥|| 100% EASY TO FOLLOW 😊|| FAST & OPTIMIZED 🔥|| CLEAN QUERY WITH NOT EXISTS 😁
beats-6411-100-easy-to-follow-fast-optim-du2l
Problem StatementI was tasked with identifying all customers from the Customers table who have never placed an order. The result should include only the names o
ahmedzubayersunny
NORMAL
2025-03-14T09:52:49.297858+00:00
2025-03-14T09:52:49.297858+00:00
439
false
# Problem Statement **I was tasked with identifying all customers from the Customers table who have never placed an order. The result should include only the names of these customers, and the output can be returned in any order.** # Code - Solution ```mssql [] SELECT name AS Customers FROM Customers c WHERE NOT EXISTS...
4
0
['Database', 'MySQL', 'MS SQL Server']
0
customers-who-never-order
MySQL Solution - Using Subquery
mysql-solution-using-subquery-by-ruch21-cfh9
Code
ruch21
NORMAL
2025-01-18T05:04:19.379036+00:00
2025-01-18T05:04:19.379036+00:00
838
false
# Code ```mysql [] # Write your MySQL query statement below SELECT name AS Customers FROM Customers WHERE id NOT IN ( SELECT customerId FROM Orders); ```
4
0
['MySQL']
1
customers-who-never-order
✅ Simple solution using LEFT JOIN ✅
simple-solution-using-left-join-by-angel-5tek
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nUsed LEFT JOIN and then
angelin_silviya
NORMAL
2024-11-10T11:10:50.937435+00:00
2024-11-10T11:10:50.937461+00:00
1,016
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nUsed LEFT JOIN and then selected the NULL rows in order to filter the customers who never ordered.\n\n\n# Code\n```postgresql []\n-- Write your PostgreSQL query statem...
4
0
['PostgreSQL']
0
customers-who-never-order
Pandas-merge-Easy Solution
pandas-merge-easy-solution-by-kg-profile-xend
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
KG-Profile
NORMAL
2024-04-19T17:59:57.042849+00:00
2024-04-19T17:59:57.042885+00:00
153
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
['Pandas']
0
customers-who-never-order
💻Think like SQL Engine🔥Solve puzzle with 2 different ways✅
think-like-sql-enginesolve-puzzle-with-2-piqk
\n# Solution with LEFT OUTER JOIN\n\n/* Write your T-SQL query statement below */\nSELECT c.name Customers\nFROM Customers c \nLEFT OUTER JOIN Orders o ON c.id
k_a_m_o_l
NORMAL
2023-12-03T06:43:44.407710+00:00
2023-12-03T06:43:44.407735+00:00
485
false
\n# Solution with LEFT OUTER JOIN\n```\n/* Write your T-SQL query statement below */\nSELECT c.name Customers\nFROM Customers c \nLEFT OUTER JOIN Orders o ON c.id = o.customerId\nWHERE o.customerId IS NULL\n```\n# Solution with NOT IN\n```\n/* Write your T-SQL query statement below */\nSELECT name Customers\nFROM Custo...
4
0
['MySQL', 'MS SQL Server']
0
customers-who-never-order
||Easy MYSQL solution without join||
easy-mysql-solution-without-join-by-amma-tztk
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
ammar_saquib
NORMAL
2023-10-26T19:19:16.911226+00:00
2023-10-26T19:19:16.911256+00:00
1,235
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
['MySQL']
0
customers-who-never-order
using isin() and negating it.
using-isin-and-negating-it-by-abdelazizs-zkz6
Intuition\n Describe your first thoughts on how to solve this problem. \n we just need to select the indicies which are not existing in the orders list\n# Appro
abdelazizSalah
NORMAL
2023-09-16T12:42:53.723550+00:00
2023-09-16T12:42:53.723574+00:00
254
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n* we just need to select the indicies which are not existing in the orders list\n# Approach\n<!-- Describe your approach to solving the problem. -->\n* First you have to know isin() function:\n * it takes a list as input, and loop over...
4
0
['Pandas']
0
customers-who-never-order
Used two approach one using simple where and one using join
used-two-approach-one-using-simple-where-ur9n
upvote if you like the solution\n\n# best approach\nselect name as customers from customers\nwhere id not in (select customerId from orders);\n\n# using joins\n
toshiksirohi
NORMAL
2023-05-04T22:06:58.179904+00:00
2023-05-04T22:06:58.179947+00:00
909
false
# upvote if you like the solution\n\n# best approach\nselect name as customers from customers\nwhere id not in (select customerId from orders);\n\n# using joins\nSELECT customers.name AS customers\nFROM customers\nLEFT JOIN orders\nON customers.id = orders.customerId\nWHERE orders.customerId IS NULL;\n\n```
4
0
['MySQL']
0
customers-who-never-order
👇 MySQL 2 solutions | very easy 🔥 nested query | join
mysql-2-solutions-very-easy-nested-query-p9nf
\uD83D\uDE4B\uD83C\uDFFB\u200D\u2640\uFE0F Hello, here are my solutions to the problem.\nPlease upvote to motivate me post future solutions. HAPPY CODING \u2764
rusgurik
NORMAL
2022-08-25T16:16:45.505465+00:00
2022-08-25T16:16:45.505513+00:00
236
false
\uD83D\uDE4B\uD83C\uDFFB\u200D\u2640\uFE0F Hello, here are my solutions to the problem.\nPlease upvote to motivate me post future solutions. HAPPY CODING \u2764\uFE0F\nAny suggestions and improvements are always welcome.\nSolution 1: Join, long, not good \uD83E\uDD26\uD83C\uDFFB\u200D\u2640\uFE0F\n\u2705 Runtime: 591 m...
4
0
['MySQL']
1
customers-who-never-order
✅ Mysql | ✅ Beginner Friendly | Fully Explained | Sub Query Concept
mysql-beginner-friendly-fully-explained-8660p
Please Upvote If you like it :)\nConcept Of the Day - Subquery\n The subquery can be nested inside a SELECT, INSERT, UPDATE, or DELETE statement or inside anoth
vikramsinghgurjar
NORMAL
2022-07-12T17:20:29.754590+00:00
2022-07-12T19:18:21.612459+00:00
190
false
**Please Upvote If you like it :)**\nConcept Of the Day - **Subquery**\n* The subquery can be nested inside a SELECT, INSERT, UPDATE, or DELETE statement or inside another subquery.\n* A subquery is usually added within the WHERE Clause of another SQL SELECT statement.\n\nHere Subquery is present in where clause\n### S...
4
0
['MySQL']
0
customers-who-never-order
A solution using NOT IN || easy to understand
a-solution-using-not-in-easy-to-understa-72si
\tSELECT Name as Customers from Customers\n\tWHERE id NOT IN(SELECT customerId from Orders)
vinita645
NORMAL
2022-06-14T06:02:05.567966+00:00
2022-06-14T06:02:05.568016+00:00
274
false
\tSELECT Name as Customers from Customers\n\tWHERE id NOT IN(SELECT customerId from Orders)
4
0
['MySQL']
1
customers-who-never-order
🔴 MySQL Solution 🔴
mysql-solution-by-alekskram-92ck
Solution\n\nselect name as Customers\nfrom Customers\nleft join Orders on Orders.customerId = Customers.id\nwhere Orders.id is null\n\nBy using left join we can
alekskram
NORMAL
2022-04-18T13:36:38.346374+00:00
2022-04-18T13:36:38.346416+00:00
143
false
# Solution\n```\nselect name as Customers\nfrom Customers\nleft join Orders on Orders.customerId = Customers.id\nwhere Orders.id is null\n```\nBy using **left join** we can see customer, who has never make orders. Orders.id will be **null**, because **join** will not find rows for them in Orders.\nIf you find this **so...
4
0
['MySQL']
0
customers-who-never-order
easy to understand
easy-to-understand-by-saurabht462-m8s8
```\nselect c.name as \'Customers\'\nfrom Customers as c\nwhere (select count(*) from Orders where Orders.customerID=c.id)=0;
saurabht462
NORMAL
2021-12-01T14:41:16.900674+00:00
2021-12-01T14:41:16.900707+00:00
184
false
```\nselect c.name as \'Customers\'\nfrom Customers as c\nwhere (select count(*) from Orders where Orders.customerID=c.id)=0;
4
0
[]
0
customers-who-never-order
left join simple
left-join-simple-by-prayaga74-5r3x
select customers.name as customers from customers left join orders on Customers.Id=Orders.CustomerId\nwhere orders.Id is null
prayaga74
NORMAL
2020-12-08T19:56:03.527523+00:00
2020-12-08T19:56:03.527564+00:00
278
false
select customers.name as customers from customers left join orders on Customers.Id=Orders.CustomerId\nwhere orders.Id is null
4
0
[]
0
customers-who-never-order
[MySQL] Simple Solution | Beats 100% in Less Space | Self-Explanatory
mysql-simple-solution-beats-100-in-less-iv5yg
\n# Write your MySQL query statement below\nselect\n c.Name as \'Customers\'\nfrom Customers c\nwhere not exists (select o.CustomerId\nfrom Orders o\nwhere c
ravireddy07
NORMAL
2020-09-10T04:13:15.317094+00:00
2020-09-10T04:16:23.516833+00:00
343
false
```\n# Write your MySQL query statement below\nselect\n c.Name as \'Customers\'\nfrom Customers c\nwhere not exists (select o.CustomerId\nfrom Orders o\nwhere c.Id = o.CustomerId);\n```
4
0
[]
0
customers-who-never-order
New simple Solution
new-simple-solution-by-mehdistudie-qllg
\nselect Name as \'Customers\' from Customers \nwhere Id not in (select distinct CustomerId from Orders);\n
mehdistudie
NORMAL
2018-04-30T16:50:35.409006+00:00
2018-04-30T16:50:35.409006+00:00
328
false
```\nselect Name as \'Customers\' from Customers \nwhere Id not in (select distinct CustomerId from Orders);\n```
4
0
[]
1
customers-who-never-order
Just a solution
just-a-solution-by-greedythief-h8jo
select Name as Customers from Customers where Customers.id not in (select CustomerId from Orders);
greedythief
NORMAL
2015-01-21T02:57:50+00:00
2015-01-21T02:57:50+00:00
1,381
false
select Name as Customers from Customers where Customers.id not in (select CustomerId from Orders);
4
0
[]
2
customers-who-never-order
A very simple solutions (Beats 100%/Runtime: 474 ms )
a-very-simple-solutions-beats-100runtime-tx8u
select Name as Customers from Customers where id not in(select CustomerId from Orders);
koyomi
NORMAL
2016-09-02T12:45:39.936000+00:00
2016-09-02T12:45:39.936000+00:00
1,440
false
select Name as Customers from Customers where id not in(select CustomerId from Orders);
4
1
[]
0
customers-who-never-order
Using "distinct" beats 99% of the solutions
using-distinct-beats-99-of-the-solutions-spi2
select \n Name \n from \n (\n select \n c.Name, \n o.CustomerId\n from Customers c \n left join (select distinct Cus
wyddfrank
NORMAL
2016-01-03T00:44:34+00:00
2016-01-03T00:44:34+00:00
1,964
false
select \n Name \n from \n (\n select \n c.Name, \n o.CustomerId\n from Customers c \n left join (select distinct CustomerId from Orders) o \n on c.Id=o.CustomerId \n ) t \n where t.CustomerId is null\n ;
4
0
[]
5
customers-who-never-order
Using one subQuery
using-one-subquery-by-mantosh_kumar04-8nep
\n\n# Code\nmysql []\n# Write your MySQL query statement below\nselect name as Customers from Customers \nwhere id not in (select customerId from Orders );\n\n
mantosh_kumar04
NORMAL
2024-10-09T15:40:25.011476+00:00
2024-10-09T15:40:25.011515+00:00
399
false
\n\n# Code\n```mysql []\n# Write your MySQL query statement below\nselect name as Customers from Customers \nwhere id not in (select customerId from Orders );\n```\n![132d8364-5b8a-490a-8f19-c223591355af_1702553187.1230645.jpeg](https://assets.leetcode.com/users/images/a4354161-3862-4cb0-92c0-68d48f0bdddb_1728488421.6...
3
0
['MySQL']
0
customers-who-never-order
MySQL Clean Solution || 2-Approach Detail Explanation
mysql-clean-solution-2-approach-detail-e-bx5s
OVERVIEW\n\n\n\n# Code\nWAY-1\n\n# Write your MySQL query statement below\nSELECT name AS Customers FROM Customers\nWHERE id NOT IN (\n SELECT customerId FRO
Shree_Govind_Jee
NORMAL
2024-05-28T04:25:27.860296+00:00
2024-05-28T04:25:27.860324+00:00
944
false
# OVERVIEW\n![430549df-fb7e-456e-af18-8f68072bdd3e_1664069167.1572943.png](https://assets.leetcode.com/users/images/9addb7e5-a31f-4237-a7ad-aae69e7353ef_1716870308.057041.png)\n\n\n# Code\n**WAY-1**\n```\n# Write your MySQL query statement below\nSELECT name AS Customers FROM Customers\nWHERE id NOT IN (\n SELECT cu...
3
0
['Database', 'MySQL']
1
customers-who-never-order
Simple LEFT JOIN With Explained Approach✔
simple-left-join-with-explained-approach-uaea
Approach\nLEFT JOIN Orders ON Customers.id = Orders.customerId, This part performs a LEFT JOIN between the "Customers" table and the "Orders" table based on the
iamsubrat1
NORMAL
2023-12-31T11:29:39.191889+00:00
2023-12-31T11:29:39.191919+00:00
1,069
false
# Approach\n**LEFT JOIN Orders ON Customers.id = Orders.customerId**, This part performs a LEFT JOIN between the **"Customers"** table and the **"Orders"** table based on the condition that the "*id"* column in the **"Customers"** table matches the *"customerId*" column in the **"Orders"** table. A LEFT JOIN returns al...
3
0
['MySQL']
1
customers-who-never-order
Easy to understand Solution for Beginners using Pandas.
easy-to-understand-solution-for-beginner-6fkd
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nchanged name of id and name column to customerId and Customers to merge t
gauravbisht126
NORMAL
2023-08-04T18:57:33.233677+00:00
2023-08-05T18:12:18.488422+00:00
182
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nchanged name of id and name column to customerId and Customers to merge the table order to customers on column customerId merge is same as merge in mysql you have to define the merge type whether outer inner left right etc. ...
3
0
['Database', 'Python3', 'Pandas']
0
customers-who-never-order
[Pandas || LEFT ANTI JOIN]
pandas-left-anti-join-by-tejkiran_v-cw8o
Left anti join selects only the rows that are present in left dataFrame as per the join-condition.\n\nIn other words, \nleft-anti-join == (left-join AND .isna
tejkiran_v
NORMAL
2023-08-04T18:01:18.208392+00:00
2023-08-04T18:01:18.208426+00:00
864
false
Left anti join selects only the rows that are present in left dataFrame as per the join-condition.\n\nIn other words, \n`left-anti-join == (left-join AND .isna())`\n\nHere we are using the pandas\' inbuilt `_merge` indicator\n# Code\n```\nimport pandas as pd\n\ndef find_customers(customers: pd.DataFrame, orders: pd....
3
0
['Pandas']
1
customers-who-never-order
An easy to understand solution
an-easy-to-understand-solution-by-delete-4gt0
Code\n\nSELECT name as Customers FROM Customers WHERE id NOT IN (SELECT customerId FROM Orders); \n
deleted_user
NORMAL
2023-07-25T08:21:29.495687+00:00
2023-07-25T08:21:54.587183+00:00
787
false
# Code\n```\nSELECT name as Customers FROM Customers WHERE id NOT IN (SELECT customerId FROM Orders); \n```
3
0
['Oracle']
0
customers-who-never-order
SQL Server CLEAN & EASY
sql-server-clean-easy-by-rhazem13-4shy
\n/* Write your T-SQL query statement below */\nSELECT name AS Customers\nFROM Customers\nWHERE id NOT IN (SELECT customerId FROM Orders)\n
rhazem13
NORMAL
2023-03-08T15:46:35.353929+00:00
2023-03-08T15:46:35.353965+00:00
1,616
false
```\n/* Write your T-SQL query statement below */\nSELECT name AS Customers\nFROM Customers\nWHERE id NOT IN (SELECT customerId FROM Orders)\n```
3
0
[]
0
customers-who-never-order
Easy SQL Query
easy-sql-query-by-yashwardhan24_sharma-xjx0
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-01T05:59:09.606611+00:00
2023-03-01T05:59:09.606659+00:00
2,178
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
customers-who-never-order
Easy MySQL || beginner solution
easy-mysql-beginner-solution-by-nikhil_m-4w64
\n# Code\n\nselect name as Customers\nfrom Customers c\nwhere id not in (select customerId from Orders);\n
nikhil_mane
NORMAL
2022-11-05T17:16:46.530443+00:00
2022-11-05T17:16:46.530492+00:00
1,637
false
\n# Code\n```\nselect name as Customers\nfrom Customers c\nwhere id not in (select customerId from Orders);\n```
3
0
['MySQL', 'MS SQL Server']
0
customers-who-never-order
Simple one line solution | mysql
simple-one-line-solution-mysql-by-gauri_-echu
SELECT name AS Customers FROM Customers WHERE id NOT IN ( Select customerId From Orders);\n\n#header is Customer in the required output ,thus using as in the qu
gauri_ajgar
NORMAL
2022-10-22T10:16:03.448587+00:00
2022-10-22T10:16:03.448631+00:00
309
false
SELECT name AS Customers FROM Customers WHERE id NOT IN ( Select customerId From Orders);\n\n#header is Customer in the required output ,thus using as in the query.
3
0
[]
0
customers-who-never-order
mysql not in
mysql-not-in-by-hailey_lai-uso5
select name as customers\nfrom customers\nwhere id not in (select customerid from orders)
Hailey_lai
NORMAL
2022-10-05T13:25:00.328417+00:00
2022-10-05T13:25:00.328466+00:00
799
false
select name as customers\nfrom customers\nwhere id not in (select customerid from orders)
3
0
['MySQL']
2
customers-who-never-order
You can do it with both sub query and join
you-can-do-it-with-both-sub-query-and-jo-vibu
/ Write your T-SQL query statement below /\n\nselect Customers.name as Customers\nfrom Customers\nleft join Orders on Customers.id= Orders.customerId\nwhere Ord
Shahzaib_Arshad
NORMAL
2022-09-25T21:52:26.376710+00:00
2022-09-25T21:52:26.376781+00:00
561
false
/* Write your T-SQL query statement below */\n\nselect Customers.name as Customers\nfrom Customers\nleft join Orders on Customers.id= Orders.customerId\nwhere Orders.customerId is null\n\n \n-- sub query \nSELECT c.Name as Customers\nFROM Customers c\nWHERE c.id not in (\nSELECT o.CustomerId FROM Orders o\n);
3
0
[]
1
customers-who-never-order
Simple Solution With Each step Explanation
simple-solution-with-each-step-explanati-g7qm
select name as Customers from Customers where id not in (select customerId from Orders);\n\n\nname as Customers: We are creating a Alias name for name in Custom
ramakm
NORMAL
2022-09-03T11:41:09.588306+00:00
2022-09-03T11:41:30.606275+00:00
375
false
```select name as Customers from Customers where id not in (select customerId from Orders);```\n\n\nname as Customers: We are creating a Alias name for name in Customer Table as Customers.\n\n(select customerId from Orders): First Select Customerid from Orders.\n\nThen check with Customer Table. So, as My final result ...
3
0
['MySQL']
1
customers-who-never-order
MsSQL one liner | Simple | Easy
mssql-one-liner-simple-easy-by-rishithar-wyi0
\nselect name as Customers from Customers where id not in (select customerId from Orders);\n
RishithaRamesh
NORMAL
2022-08-16T07:17:57.463136+00:00
2022-08-16T07:17:57.463189+00:00
631
false
```\nselect name as Customers from Customers where id not in (select customerId from Orders);\n```
3
0
['MS SQL Server']
0
customers-who-never-order
Faster Than 99.67% | Subquery
faster-than-9967-subquery-by-manishbaswa-lr0c
\nselect name as customers from Customers where id not in (select customerId from Orders);\n\n
manishbaswal6
NORMAL
2022-08-05T18:24:52.617102+00:00
2022-08-05T18:25:36.543504+00:00
279
false
```\nselect name as customers from Customers where id not in (select customerId from Orders);\n\n```
3
0
[]
0
customers-who-never-order
easy 2-liner sql solution
easy-2-liner-sql-solution-by-dhruvraj_05-vvi6
\n SELECT Name AS Customers FROM CUSTOMERS LEFT JOIN ORDERS ON ORDERS.CustomerID = Customers.Id\n WHERE Orders.CustomerID IS NULL
Dhruvraj_05
NORMAL
2022-07-29T04:36:14.131268+00:00
2022-07-29T04:36:14.131308+00:00
546
false
\n* SELECT Name AS Customers FROM CUSTOMERS LEFT JOIN ORDERS ON ORDERS.CustomerID = Customers.Id\n* WHERE Orders.CustomerID IS NULL
3
0
['Oracle']
0
customers-who-never-order
SQL | LEFT JOIN
sql-left-join-by-madsteins-wg3r
\nSELECT NAME AS \'CUSTOMERS\'FROM CUSTOMERS LEFT JOIN ORDERS\nON CUSTOMERS.ID = ORDERS.CUSTOMERID\nWHERE ORDERS.CUSTOMERID IS NULL\n
MadSteins
NORMAL
2022-05-29T20:17:59.730753+00:00
2022-05-29T20:17:59.730800+00:00
283
false
```\nSELECT NAME AS \'CUSTOMERS\'FROM CUSTOMERS LEFT JOIN ORDERS\nON CUSTOMERS.ID = ORDERS.CUSTOMERID\nWHERE ORDERS.CUSTOMERID IS NULL\n```
3
0
['MySQL']
1
customers-who-never-order
✅ [Accepted] Solution for MySQL | Clean & Simple Code
accepted-solution-for-mysql-clean-simple-k86w
\nSELECT name AS Customers FROM Customers \nWHERE id NOT IN (SELECT customerId FROM Orders);\n
axitchandora
NORMAL
2022-05-15T16:23:03.315949+00:00
2022-05-23T10:50:43.096599+00:00
272
false
```\nSELECT name AS Customers FROM Customers \nWHERE id NOT IN (SELECT customerId FROM Orders);\n```
3
0
['MySQL']
0
customers-who-never-order
Simple SQL query
simple-sql-query-by-sathwikamadarapu-b0ob
```\nselect c.name as Customers\nfrom Customers c\nwhere c.id Not In (select customerId from Orders );
SATHWIKAMADARAPU
NORMAL
2022-05-02T11:53:18.864593+00:00
2022-05-02T11:53:18.864638+00:00
256
false
```\nselect c.name as Customers\nfrom Customers c\nwhere c.id Not In (select customerId from Orders );
3
0
['MySQL']
0
customers-who-never-order
183. Customers Who Never Order
183-customers-who-never-order-by-shubham-jvnx
\nselect name as customers from customers AS c\nleft join orders AS O\nON c.ID = o.customerID where o.customerId is null;\n
shubham_pcs2012
NORMAL
2022-04-20T05:39:14.531618+00:00
2022-04-20T05:39:14.531645+00:00
306
false
```\nselect name as customers from customers AS c\nleft join orders AS O\nON c.ID = o.customerID where o.customerId is null;\n```
3
0
['MySQL']
0
customers-who-never-order
Easy Solution using Sub-query
easy-solution-using-sub-query-by-tejaspr-kng2
Approach\n Since we have the CustomerId column as a foreign key in the Orders table, we need to find all those customers whose Id is not present in CustomerId c
tejaspradhan
NORMAL
2021-07-12T17:33:07.193116+00:00
2021-07-12T17:34:58.229191+00:00
238
false
**Approach**\n* Since we have the CustomerId column as a foreign key in the Orders table, we need to find all those customers whose Id is not present in CustomerId column of Orders table. \n* This in turn means that they haven\'t ordered anything.\n* So, first we write a sub-query to find all the CustomerIds present in...
3
0
['MySQL']
0
customers-who-never-order
A very intuitive and simple solution. Memory: 0B, less than 100.00%
a-very-intuitive-and-simple-solution-mem-25eu
```\nSELECT Name as Customers \nFROM Customers\nWHERE id not in (SELECT CustomerId FROM Orders)
m-d-f
NORMAL
2021-02-18T12:04:35.542903+00:00
2021-02-18T12:04:35.542942+00:00
223
false
```\nSELECT Name as Customers \nFROM Customers\nWHERE id not in (SELECT CustomerId FROM Orders)
3
0
['MySQL']
0
customers-who-never-order
MySQL, LEFT JOIN()
mysql-left-join-by-leovam-x73d
\n# Write your MySQL query statement below\nSELECT\n c.name AS customers\nFROM\n customers AS c\nLEFT JOIN \n orders AS o\nON o.customerid = c.id\nWHER
leovam
NORMAL
2021-01-20T04:03:59.763792+00:00
2021-01-20T04:03:59.763842+00:00
331
false
```\n# Write your MySQL query statement below\nSELECT\n c.name AS customers\nFROM\n customers AS c\nLEFT JOIN \n orders AS o\nON o.customerid = c.id\nWHERE\n o.customerid IS NULL\n\n```
3
0
['MySQL']
0
customers-who-never-order
SELECT name AS Customers FROM Customers WHERE id NOT IN ( SELECT customerId FROM Orders );
select-name-as-customers-from-customers-730tm
Code
Vishal1431
NORMAL
2025-02-03T18:49:35.628642+00:00
2025-02-03T18:49:35.628642+00:00
342
false
# Code ```mysql [] SELECT name AS Customers FROM Customers WHERE id NOT IN ( SELECT customerId FROM Orders ); ```
2
0
['MySQL']
0
customers-who-never-order
Left Join
left-join-by-ramsingh27-8enw
IntuitionApproachComplexity Time complexity: Space complexity: Code
Ramsingh27
NORMAL
2024-12-24T07:41:22.242008+00:00
2024-12-24T07:41:22.242008+00:00
413
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
['MySQL']
0
customers-who-never-order
2 solutions ( 1 more faster code)
2-solutions-1-more-faster-code-by-devdis-d0ie
Code\nmssql []\n-- \u2B50 1. using left join concept\nSELECT C.n[ame AS Customers \nFROM Customers AS C LEFT JOIN Orders AS O\nON C.id = O.customerId \nWHERE O.
DevDish
NORMAL
2024-09-20T11:07:03.859493+00:00
2024-09-20T11:07:03.859514+00:00
38
false
# Code\n```mssql []\n-- \u2B50 1. using left join concept\nSELECT C.n[ame AS Customers \nFROM Customers AS C LEFT JOIN Orders AS O\nON C.id = O.customerId \nWHERE O.customerId IS NULL]()\n\n-- \u2B50 2. more optimised/faster code\nSELECT name AS Customers \nFROM Customers \nWHERE id NOT IN (SELECT customerId FROM Order...
2
0
['MS SQL Server']
1
customers-who-never-order
Customers Who Never Order
customers-who-never-order-by-tejdekiwadi-edps
Intuition\nThe goal is to find customers who have not placed any orders. By joining the customers table with the orders table using a LEFT JOIN and filtering fo
tejdekiwadiya
NORMAL
2024-06-28T20:07:04.063970+00:00
2024-06-28T20:07:04.064004+00:00
529
false
# Intuition\nThe goal is to find customers who have not placed any orders. By joining the `customers` table with the `orders` table using a LEFT JOIN and filtering for records where there is no corresponding `customerId` in the `orders` table, we can identify these customers.\n\n# Approach\n1. **LEFT JOIN**: Perform a ...
2
0
['Database', 'MySQL']
0
customers-who-never-order
🚀🚀beats 85% || ✅✅Easy approach
beats-85-easy-approach-by-u23cs159-k2qv
\n\n\n# Intuition\n Describe your first thoughts on how to solve this problem. \n\uD83C\uDFAFImagine you run a store and want to identify which of your customer
u23cs159
NORMAL
2024-06-07T09:40:51.422921+00:00
2024-06-07T09:40:51.422950+00:00
886
false
![Screenshot 2024-06-07 150912.png](https://assets.leetcode.com/users/images/c25f6590-4d52-44ee-8671-5e94c6a406b2_1717753169.6670876.png)\n\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\uD83C\uDFAFImagine you run a store and want to identify which of your customers have never mad...
2
0
['Python3', 'Pandas']
0
find-duplicate-subtrees
Java Concise Postorder Traversal Solution
java-concise-postorder-traversal-solutio-rsvj
We perform postorder traversal, serializing and hashing the serials of subtrees in the process. We can recognize a duplicate subtree by its serialization.\n\n\n
compton_scatter
NORMAL
2017-07-30T03:06:07.745000+00:00
2020-12-06T00:05:41.850378+00:00
79,332
false
We perform postorder traversal, serializing and hashing the serials of subtrees in the process. We can recognize a duplicate subtree by its serialization.\n\n```\npublic List<TreeNode> findDuplicateSubtrees(TreeNode root) {\n List<TreeNode> res = new LinkedList<>();\n postorder(root, new HashMap<>(), res);\n r...
459
11
[]
117
find-duplicate-subtrees
O(n) time and space, lots of analysis
on-time-and-space-lots-of-analysis-by-st-wu1s
First the basic version, which is O(n2) time and gets accepted in about 150 ms:\n\n def findDuplicateSubtrees(self, root):\n def tuplify(root):\n
stefanpochmann
NORMAL
2017-07-30T04:17:32.670000+00:00
2018-10-06T15:10:14.065220+00:00
51,182
false
First the basic version, which is O(n<sup>2</sup>) time and gets accepted in about 150 ms:\n\n def findDuplicateSubtrees(self, root):\n def tuplify(root):\n if root:\n tuple = root.val, tuplify(root.left), tuplify(root.right)\n trees[tuple].append(root)\n ...
385
7
[]
22
find-duplicate-subtrees
[C++] [Java] Clean Code with Explanation
c-java-clean-code-with-explanation-by-al-ncds
Description\n\nGiven the root of a binary tree, return all duplicate subtrees.\n\nFor each kind of duplicate subtrees, you only need to return the root node of
alexander
NORMAL
2017-07-30T03:25:45.643000+00:00
2020-08-23T00:09:12.270276+00:00
38,338
false
## Description\n\nGiven the `root` of a binary tree, return all `duplicate subtrees`.\n\nFor each kind of duplicate subtrees, you only need to return the root node of any one of them.\n\nTwo trees are duplicate if they have the same structure with the same node values.\n\n\n## Analysis\n\n- A unique sub-tree can be uni...
255
6
[]
27
find-duplicate-subtrees
Python easy understand solution
python-easy-understand-solution-by-lee21-edsi
`````\ndef findDuplicateSubtrees(self, root):\n def trv(root):\n if not root: return "null"\n struct = "%s,%s,%s" % (str(root.val),
lee215
NORMAL
2017-07-30T10:41:47.454000+00:00
2018-10-23T19:17:59.280825+00:00
31,354
false
`````\ndef findDuplicateSubtrees(self, root):\n def trv(root):\n if not root: return "null"\n struct = "%s,%s,%s" % (str(root.val), trv(root.left), trv(root.right))\n nodes[struct].append(root)\n return struct\n \n nodes = collections.defaultdict(list)\n ...
204
13
[]
26
find-duplicate-subtrees
Python solution explained in two steps - for beginners
python-solution-explained-in-two-steps-f-2qy6
Lets divide the problem into two:\n\nOverview: We need to somehow serialize the tree for every node in the tree. Then in a hash map (dict), we need to increment
ikna
NORMAL
2021-11-11T05:01:30.073865+00:00
2021-11-11T05:03:20.666887+00:00
7,468
false
Lets divide the problem into two:\n\n**Overview**: We need to somehow serialize the tree for every node in the tree. Then in a hash map (dict), we need to increment the count when serialization from another matches the existing key in hmap. \n\n```\n\t\t\t1\n\t\t2 3\n```\nIf we serialize from each node, the output ...
159
1
['Python']
11
find-duplicate-subtrees
Java || Easy Approach with Explanation || HashMap || Postorder
java-easy-approach-with-explanation-hash-6hx9
\nclass Solution \n{\n HashMap<String, Integer> map= new HashMap<>();//String -- frequency//it store the string at every instant when we visit parent after v
swapnilGhosh
NORMAL
2021-07-29T14:38:48.524727+00:00
2021-07-29T14:39:40.957368+00:00
8,749
false
```\nclass Solution \n{\n HashMap<String, Integer> map= new HashMap<>();//String -- frequency//it store the string at every instant when we visit parent after visiting its children //it also calculates the frequency of the String in the tree\n ArrayList<TreeNode> res= new ArrayList<>();//it contain the list of du...
136
2
['Depth-First Search', 'Recursion', 'Java']
3
find-duplicate-subtrees
✅ Java | Easy | HashMap | With Explanation
java-easy-hashmap-with-explanation-by-ka-a6tv
The basic intuition is to find the duplicate subtrees of the given tree. So here we just used a hashmap and we can use preorder or postorder traversal to form t
kalinga
NORMAL
2023-02-28T01:39:09.540183+00:00
2023-02-28T01:39:09.540219+00:00
10,168
false
**The basic intuition is to find the duplicate subtrees of the given tree. So here we just used a hashmap and we can use preorder or postorder traversal to form the subtrees of string type and will check if they are already present in hashmap. If they are not present then we will simply insert into hashmap and keep on ...
124
0
['Tree', 'Depth-First Search', 'Recursion', 'Binary Tree', 'Java']
6
find-duplicate-subtrees
8 lines C++
8-lines-c-by-zefengsong-bwu1
\nclass Solution {\npublic:\n vector<TreeNode*> findDuplicateSubtrees(TreeNode* root) {\n unordered_map<string, int>m;\n vector<TreeNode*>res;\
zefengsong
NORMAL
2017-10-15T05:10:58.973000+00:00
2018-10-17T15:00:36.163674+00:00
12,067
false
```\nclass Solution {\npublic:\n vector<TreeNode*> findDuplicateSubtrees(TreeNode* root) {\n unordered_map<string, int>m;\n vector<TreeNode*>res;\n DFS(root, m, res);\n return res;\n }\n \n string DFS(TreeNode* root, unordered_map<string, int>& m, vector<TreeNode*>& res){\n ...
105
2
['C++']
13
find-duplicate-subtrees
✌️🟢C++ EASIEST SOLUTION WITH COMPLETE EXPLANATION EASY TO UNDERSTAND
c-easiest-solution-with-complete-explana-pbxr
Intuition\nThe problem asks to find duplicate subtrees in a given binary tree. Two trees are considered duplicate if they have the same structure and node value
suryansh_639
NORMAL
2023-02-28T00:25:05.899447+00:00
2023-02-28T04:45:50.666285+00:00
14,941
false
# Intuition\nThe problem asks to find duplicate subtrees in a given binary tree. Two trees are considered duplicate if they have the same structure and node values. The task is to return any one of the duplicate subtrees.\n\nTo solve this problem, we can use a post-order traversal of the binary tree and serialize the s...
95
3
['C++']
8
find-duplicate-subtrees
simple c++ solution | unordered-map | 97% faster
simple-c-solution-unordered-map-97-faste-7e8q
\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0)
xor09
NORMAL
2021-02-14T05:05:58.783908+00:00
2021-02-14T05:05:58.783941+00:00
5,624
false
```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right...
68
1
['C']
6
find-duplicate-subtrees
Python, O(N) Merkle Hashing Approach
python-on-merkle-hashing-approach-by-awi-h16z
We'll assign every subtree a unique merkle hash. You can find more information about Merkle tree hashing here: https://discuss.leetcode.com/topic/88520/python
awice
NORMAL
2017-07-30T03:43:28.023000+00:00
2017-07-30T03:43:28.023000+00:00
11,340
false
We'll assign every subtree a unique *merkle* hash. You can find more information about Merkle tree hashing here: https://discuss.leetcode.com/topic/88520/python-straightforward-with-explanation-o-st-and-o-s-t-approaches\n\n```\ndef findDuplicateSubtrees(self, root):\n from hashlib import sha256\n def hash_(x):\...
61
1
[]
10
find-duplicate-subtrees
Clean Codes🔥🔥|| Full Explanation✅|| Depth First Search✅|| C++|| Java|| Python3
clean-codes-full-explanation-depth-first-yn8v
Intuition :\n- Here we have to find all the subtrees in a binary tree that occur more than once and return their roots.\n Describe your first thoughts on how to
N7_BLACKHAT
NORMAL
2023-02-28T02:20:02.011222+00:00
2023-03-01T02:28:41.612228+00:00
7,853
false
# Intuition :\n- Here we have to find all the subtrees in a binary tree that occur more than once and return their roots.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Detail Explanation to Approach :\n- Here we are using a `depth-first search` approach to traverse the tree and encode each s...
59
0
['Depth-First Search', 'Python', 'C++', 'Java', 'Python3']
5
find-duplicate-subtrees
No string hash, Python code, O(n) time and space
no-string-hash-python-code-on-time-and-s-u0rg
\n def findDuplicateSubtrees(self, root):\n self.type_id_gen = 0\n duplicated_subtrees = []\n type_to_freq = defaultdict(int)\n t
danile
NORMAL
2017-07-31T03:30:05.685000+00:00
2018-10-21T03:13:17.473252+00:00
9,866
false
```\n def findDuplicateSubtrees(self, root):\n self.type_id_gen = 0\n duplicated_subtrees = []\n type_to_freq = defaultdict(int)\n type_to_id = {}\n \n def dfs(node):\n if not node:\n return -1\n type_id_left, type_id_right = (dfs(ch) for...
57
1
[]
5
find-duplicate-subtrees
Javascript Postorder DFS
javascript-postorder-dfs-by-fbecker11-4w5d
\nvar findDuplicateSubtrees = function(root) {\n const map = new Map(), res = []\n dfs(root, map, res)\n return res\n};\n\nfunction dfs(root, map, res){\n i
fbecker11
NORMAL
2020-09-27T14:36:33.602608+00:00
2020-09-27T14:36:33.602655+00:00
2,528
false
```\nvar findDuplicateSubtrees = function(root) {\n const map = new Map(), res = []\n dfs(root, map, res)\n return res\n};\n\nfunction dfs(root, map, res){\n if(!root) return \'#\'\n const subtree = `${root.val}.${dfs(root.left,map,res)}.${dfs(root.right, map,res)}`\n map.set(subtree,(map.get(subtree)||0) + 1)\n ...
35
0
['Depth-First Search', 'JavaScript']
8
find-duplicate-subtrees
C++ easy traversing solution with comments
c-easy-traversing-solution-with-comments-119c
PLEASE UPVOTE IF IT HELPS A BIT\n```\n\nclass Solution {\npublic:\n vector ans;\n unordered_mapmymap;\n string helper(TreeNode root)\n {\n if
code77777
NORMAL
2022-01-05T13:19:57.104949+00:00
2022-01-05T13:19:57.104995+00:00
2,309
false
**PLEASE UPVOTE IF IT HELPS A BIT**\n```\n\nclass Solution {\npublic:\n vector<TreeNode*> ans;\n unordered_map<string, int>mymap;\n string helper(TreeNode* root)\n {\n if(root == NULL) return "";\n \n string l= helper(root->left);\n string r= helper(root->right);\n string ...
32
0
['C']
4
find-duplicate-subtrees
C++ 15ms (< 99.76%)
c-15ms-9976-by-huahualeetcode-z4vk
Running Time: 15 ms (< 99.76%)\nC++\nUse \n(root.val << 32) | (id(root.left) << 16) | id(root.right) \nas a 64 bit key, supports up to 65535 unique nodes\n\n\nC
huahualeetcode
NORMAL
2018-01-01T00:43:22.517000+00:00
2019-05-08T04:16:44.201849+00:00
3,898
false
Running Time: 15 ms (< 99.76%)\n```C++\nUse \n(root.val << 32) | (id(root.left) << 16) | id(root.right) \nas a 64 bit key, supports up to 65535 unique nodes\n```\n\n```C++\nclass Solution {\npublic:\n vector<TreeNode*> findDuplicateSubtrees(TreeNode* root) {\n unordered_map<long, pair<int,int>> counts; \n vec...
23
3
[]
11
find-duplicate-subtrees
Python code easy to understand, postorder traversal + serialization
python-code-easy-to-understand-postorder-zz29
\n# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# s
kitt
NORMAL
2017-07-30T04:10:28.898000+00:00
2017-07-30T04:10:28.898000+00:00
2,775
false
```\n# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def postorder(self, node):\n """\n :type node: TreeNode\n :rtype: str\n """\n ...
22
4
[]
3
find-duplicate-subtrees
Post-order Traversal + Post-order/Pre-order Serialization
post-order-traversal-post-orderpre-order-w5c7
We can serialize subtrees while traversing the tree, and then compare the serializations to see if there are duplicates.\n\nThe post-order traversal is natural
gracemeng
NORMAL
2018-05-04T09:06:13.376240+00:00
2021-05-12T20:22:15.474114+00:00
2,917
false
We can serialize subtrees while traversing the tree, and then compare the serializations to see if there are duplicates.\n\nThe post-order traversal is natural here.\n\nAs for the construction of the serialization string, we can apply either the pre-order or the post-order. The in-order is inappropriate here because tr...
21
2
[]
5
find-duplicate-subtrees
Easy + Clean + Straightforward Python Recursive
easy-clean-straightforward-python-recurs-j58t
\nclass Solution:\n def findDuplicateSubtrees(self, root: TreeNode) -> List[TreeNode]:\n \n seen = collections.defaultdict(int)\n res =
pythagoras_the_3rd
NORMAL
2021-04-27T05:16:00.520547+00:00
2021-04-27T05:18:12.054781+00:00
2,410
false
```\nclass Solution:\n def findDuplicateSubtrees(self, root: TreeNode) -> List[TreeNode]:\n \n seen = collections.defaultdict(int)\n res = []\n \n def helper(node):\n if not node:\n return\n sub = tuple([helper(node.left), node.val, helper(node....
20
0
['Recursion', 'Python', 'Python3']
3
find-duplicate-subtrees
Verbose Java solution, tree traversal
verbose-java-solution-tree-traversal-by-0831z
Idea is to traverse the tree and serialize each sub-tree to a string and put them into a HashMap. The first time we put null as the value and later we put the r
shawngao
NORMAL
2017-07-30T03:10:06.693000+00:00
2018-10-08T07:39:29.931539+00:00
7,959
false
Idea is to traverse the tree and serialize each sub-tree to a string and put them into a HashMap. The first time we put ```null``` as the value and later we put the real node as the value. Then at last, every entry in the map with not null value, is an answer.\nAn optimization is to start searching from the ```first po...
18
0
[]
7
find-duplicate-subtrees
C++ || Easy and Concise Inorder Traversal
c-easy-and-concise-inorder-traversal-by-hw5k3
\nstring inorder(TreeNode* root, unordered_map<string, int>& mp, vector<TreeNode*>& res) \n{\n if(!root)\n return "";\n\n s
suniti0804
NORMAL
2021-06-08T04:57:05.930396+00:00
2021-06-08T04:57:05.930442+00:00
1,994
false
```\nstring inorder(TreeNode* root, unordered_map<string, int>& mp, vector<TreeNode*>& res) \n{\n if(!root)\n return "";\n\n string str = "(";\n str += inorder(root -> left, mp, res);\n str += to_string(root -> val);\n str += inorder(root -> right, mp, res);\n ...
17
0
['C', 'C++']
2
find-duplicate-subtrees
Optimised and simple solution in JavaScript.
optimised-and-simple-solution-in-javascr-yydu
\n# Approach\n1) Define a recursive function to traverse the binary tree. The function should take a node as input and return a string representation of the sub
AdiCoder95
NORMAL
2023-02-28T03:33:04.884287+00:00
2023-02-28T03:33:04.884331+00:00
620
false
\n# Approach\n1) Define a recursive function to traverse the binary tree. The function should take a node as input and return a string representation of the subtree rooted at that node.\n2) In the "traverse" function, if the node is null, return a special symbol to represent it.\n3) Construct a string representation of...
11
0
['Hash Table', 'Binary Tree', 'JavaScript']
1
find-duplicate-subtrees
🧐Look at once 💻 🔥Solutions in Java 📝, Python 🐍, and C++ 🖥️ with Video Explanation 🎥
look-at-once-solutions-in-java-python-an-badv
Intuition\n Describe your first thoughts on how to solve this problem. \nTo find duplicate subtrees, we can traverse the binary tree using depth-first search (D
Vikas-Pathak-123
NORMAL
2023-02-28T03:15:17.303000+00:00
2023-02-28T03:15:17.303045+00:00
1,385
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo find duplicate subtrees, we can traverse the binary tree using depth-first search (DFS) and store the subtree\'s serialized representation in a map, where the key is the serialized string, and the value is a list of tree nodes that rep...
11
0
['Hash Table', 'Depth-First Search', 'Python', 'C++', 'Java']
1
find-duplicate-subtrees
Best Python Solution (not serializing entire tree!!!)
best-python-solution-not-serializing-ent-bvj5
Most python solutions are serializing the entire tree into a string and using that as a unique key. That makes it O(n^2) space complexity. This is a much better
mcmar
NORMAL
2021-06-03T21:52:16.637264+00:00
2021-06-03T21:52:16.637296+00:00
1,277
false
Most python solutions are serializing the entire tree into a string and using that as a unique key. That makes it `O(n^2)` space complexity. This is a much better solution that is `O(n)` space complexity. Instead, I map each `(node.val, left_id, right_id)` to a new unique id that I return for the parent to use. Now eac...
11
0
['Python']
1
find-duplicate-subtrees
Easy Java Solution 100% faster || With Algorithm in steps || Super Easy to understand
easy-java-solution-100-faster-with-algor-l87q
\n\n# Intuition\n Describe your first thoughts on how to solve this problem. \nThe intuition behind this solution is to use depth-first search (DFS) to traverse
Yaduttam_Pareek
NORMAL
2023-02-28T02:36:42.349485+00:00
2023-02-28T02:36:42.349515+00:00
1,697
false
![image.png](https://assets.leetcode.com/users/images/2205db22-2e2e-46c5-ba60-9eeebc11dd96_1677551740.0497117.png)\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition behind this solution is to use depth-first search (DFS) to traverse the binary tree and store information ...
10
0
['Java']
0
find-duplicate-subtrees
Simple C++ Solution || O(n) || postOrder
simple-c-solution-on-postorder-by-samaha-70r9
\n# Complexity\n- Time complexity:O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(n)\n Add your space complexity here, e.g. O(n) \n\n#
samahakal04
NORMAL
2022-11-07T07:32:03.939198+00:00
2022-11-07T07:32:03.939247+00:00
1,403
false
\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *rig...
9
1
['String', 'Tree', 'Binary Tree', 'C++']
4
find-duplicate-subtrees
Go 12ms 100% map solution
go-12ms-100-map-solution-by-tjucoder-2kte
go\nfunc findDuplicateSubtrees(root *TreeNode) []*TreeNode {\n\thashAll := map[string]int{}\n\tduplicate := []*TreeNode{}\n\tdfs(root, hashAll, &duplicate)\n\tr
tjucoder
NORMAL
2020-09-12T18:03:52.983083+00:00
2020-09-12T18:03:52.983129+00:00
506
false
```go\nfunc findDuplicateSubtrees(root *TreeNode) []*TreeNode {\n\thashAll := map[string]int{}\n\tduplicate := []*TreeNode{}\n\tdfs(root, hashAll, &duplicate)\n\treturn duplicate\n}\n\nfunc dfs(node *TreeNode, hashAll map[string]int, duplicate *[]*TreeNode) string {\n\tif node == nil {\n\t\treturn "nil"\n\t}\n lStri...
9
0
['Go']
0
find-duplicate-subtrees
easy peasy recursive preorder solution
easy-peasy-recursive-preorder-solution-b-coo7
\tdef findDuplicateSubtrees(self, root: TreeNode) -> List[TreeNode]:\n if root is None:\n return []\n self.mp = {}\n self.rs = [
lostworld21
NORMAL
2019-09-22T00:37:59.388511+00:00
2019-09-22T00:37:59.388549+00:00
2,106
false
\tdef findDuplicateSubtrees(self, root: TreeNode) -> List[TreeNode]:\n if root is None:\n return []\n self.mp = {}\n self.rs = []\n self.preorder(root)\n return self.rs\n \n def preorder(self, root):\n if root:\n ls = str(root.val) + "-" + self.preor...
9
0
['Tree', 'Depth-First Search', 'Python', 'Python3']
3
find-duplicate-subtrees
C++ O(n) time & space - 8ms beats 100% and scales to 2^64 unique nodes
c-on-time-space-8ms-beats-100-and-scales-q4h5
This solution builds up on the fantastic work of @Danile, @StefanPochman. This C++ implmentation uses a bitset that encodes the root\'s value in the most signif
v1s1on
NORMAL
2019-01-26T03:08:54.552773+00:00
2019-01-26T03:08:54.552821+00:00
1,285
false
This solution builds up on the fantastic work of @Danile, @StefanPochman. This C++ implmentation uses a bitset that encodes the root\'s value in the most significant bits, followed by a concatenation of the left\'s node id and the right node\'s id. Since these node id\'s are actually just an incremened counter we can h...
9
1
[]
2
find-duplicate-subtrees
Python solution
python-solution-by-zitaowang-z424
\nclass Solution(object):\n def findDuplicateSubtrees(self, root):\n """\n :type root: TreeNode\n :rtype: List[TreeNode]\n """\n
zitaowang
NORMAL
2018-11-13T17:58:24.932135+00:00
2018-11-13T17:58:24.932180+00:00
897
false
```\nclass Solution(object):\n def findDuplicateSubtrees(self, root):\n """\n :type root: TreeNode\n :rtype: List[TreeNode]\n """\n def helper(root):\n if not root:\n return "None,"\n l = helper(root.left)\n r = helper(root.right)\n ...
8
0
[]
3
find-duplicate-subtrees
Java - Super easy postorder with HashMap<String, TreeNode> solution
java-super-easy-postorder-with-hashmapst-3lwy
No fancy tricks, just a post order traversal.\nUse HashMap to store the founded subtree and its root node. Use postorder traversal to get the left and right sub
wei-cheng
NORMAL
2017-07-30T19:30:04.198000+00:00
2018-08-26T23:19:51.213985+00:00
2,479
false
No fancy tricks, just a post order traversal.\nUse HashMap<String, TreeNode> to store the founded subtree and its root node. Use postorder traversal to get the left and right subtree and form the full subtree string with the current node. If the subtree is found first time, put <postorder string, null>. If the subtree ...
8
1
[]
5
find-duplicate-subtrees
C++ Easy solution | Beats 95% | unordered map | post order traversal
c-easy-solution-beats-95-unordered-map-p-q49i
Approach\n Store a node\'s value + it\'s child values recursively in form of string. check if this string already exists in unordered map. \nIf this string exis
Jaswanth_9989
NORMAL
2023-02-28T07:16:15.021538+00:00
2023-02-28T07:16:15.021566+00:00
1,979
false
# Approach\n Store a node\'s value + it\'s child values recursively in form of string. check if this string already exists in unordered map. \nIf this string exists in map, push the node into v(answer vector).\nelse add this string into map. \n<!-- Describe your approach to solving the problem. -->\n\n# Code\n```\n/**\...
7
1
['C++']
0
find-duplicate-subtrees
Python | DFS, Dictionary | O(n) time, O(n) space
python-dfs-dictionary-on-time-on-space-b-gw0n
\n# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.lef
Kiyomi_
NORMAL
2022-05-07T13:21:43.096955+00:00
2022-05-16T06:58:14.297938+00:00
1,437
false
```\n# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findDuplicateSubtrees(self, root: Optional[TreeNode]) -> List[Optional[TreeNode]]:\n ...
7
0
['Tree', 'Depth-First Search', 'Python', 'Python3']
3
find-duplicate-subtrees
Easy java dfs code
easy-java-dfs-code-by-legit_123-tgky
Uniquely identify each subtree by a String key , and if that key occurs more than once , then the subtree to which that key is mapped is a duplicate subtree \n\
legit_123
NORMAL
2021-10-06T05:04:03.797876+00:00
2021-10-06T05:04:03.797927+00:00
1,191
false
Uniquely identify each subtree by a String key , and if that key occurs more than once , then the subtree to which that key is mapped is a duplicate subtree \n\n```\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() ...
7
0
['Depth-First Search', 'Java']
3
find-duplicate-subtrees
[c++] easy to understand hashing based solution
c-easy-to-understand-hashing-based-solut-aezi
\nclass Solution {\npublic:\n \n unordered_map<string,vector<TreeNode*>>mp;\n \n string recurs(TreeNode* root)\n {\n if(root==NULL)\n
SJ4u
NORMAL
2021-06-30T05:26:56.190153+00:00
2021-06-30T05:28:06.463703+00:00
1,027
false
```\nclass Solution {\npublic:\n \n unordered_map<string,vector<TreeNode*>>mp;\n \n string recurs(TreeNode* root)\n {\n if(root==NULL)\n return "";\n string a=recurs(root->left);\n string b=recurs(root->right);\n \n string temp="";\n temp+=to_string(ro...
7
0
['Depth-First Search', 'C', 'C++']
1
find-duplicate-subtrees
🗓️ Daily LeetCoding Challenge February, Day 28
daily-leetcoding-challenge-february-day-nw46h
This problem is the Daily LeetCoding Challenge for February, Day 28. Feel free to share anything related to this problem here! You can ask questions, discuss wh
leetcode
OFFICIAL
2023-02-28T00:00:19.128545+00:00
2023-02-28T00:00:19.128614+00:00
7,930
false
This problem is the Daily LeetCoding Challenge for February, Day 28. Feel free to share anything related to this problem here! You can ask questions, discuss what you've learned from this problem, or show off how many days of streak you've made! --- If you'd like to share a detailed solution to the problem, please ...
6
1
[]
47
find-duplicate-subtrees
short c++ solution
short-c-solution-by-sandeep_003-2w8j
\n unordered_map<string,int> m;\n vector<TreeNode*> v;\n vector<TreeNode*> findDuplicateSubtrees(TreeNode* root) {\n solve(root);\n return v;
sandeep_003
NORMAL
2021-08-25T07:18:06.661544+00:00
2021-08-25T07:18:06.661590+00:00
419
false
```\n unordered_map<string,int> m;\n vector<TreeNode*> v;\n vector<TreeNode*> findDuplicateSubtrees(TreeNode* root) {\n solve(root);\n return v;\n }\n string solve(TreeNode* root)\n {\n if(root==nullptr) return "#";\n string s="";\n s=s+to_string(root->val)+\',\';\n ...
6
0
[]
0
find-duplicate-subtrees
Java Easy to Understand Solution with Explanation
java-easy-to-understand-solution-with-ex-c9ag
Intuition consists of 3 steps:\n\n1) Create a signature for each node. \n2) Add node to the result if you have already seen that signature before.\n3) Make sure
kamaci
NORMAL
2021-06-13T08:29:49.859866+00:00
2021-06-13T08:29:49.859909+00:00
1,182
false
Intuition consists of 3 steps:\n\n1) Create a signature for each node. \n2) Add node to the result if you have already seen that signature before.\n3) Make sure to add prefix for sub-left tree and sub-right tree representations in order to avoid some cases at which signature are same but trees are not duplicate.\n\n```...
6
0
['Depth-First Search', 'Java']
0
find-duplicate-subtrees
EASY JAVASCRIPT SOLUTION!!
easy-javascript-solution-by-hanseaston-vs28
\nvar findDuplicateSubtrees = function(root) {\n const rtn = [];\n\t// Map keeping track of the subtrees\n const map = new Map();\n const helper = root
hanseaston
NORMAL
2020-07-03T04:44:46.653136+00:00
2020-07-03T04:47:33.787402+00:00
359
false
```\nvar findDuplicateSubtrees = function(root) {\n const rtn = [];\n\t// Map keeping track of the subtrees\n const map = new Map();\n const helper = root => {\n\t // Use "#" to represent null nodes\n if (!root) return "#";\n\t\t// Adding "." is necessary, for ex, differentiating "1" and "11"\n ...
6
0
[]
0
find-duplicate-subtrees
[Python] Serialization (Easy Understanding)
python-serialization-easy-understanding-p20sf
\n# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.righ
ruifeng_wang
NORMAL
2020-02-23T01:59:20.868071+00:00
2020-02-23T01:59:20.868131+00:00
602
false
```\n# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nfrom collections import defaultdict\n\nclass Solution:\n def findDuplicateSubtrees(self, root: TreeNode) -> List[TreeNode]:\n \n ...
6
3
['Python3']
4
find-duplicate-subtrees
C++, 19 ms, O(n^2), sort by subtree height
c-19-ms-on2-sort-by-subtree-height-by-ze-vfbi
If two subtrees are the same, they have to have same height. The idea is to sort subtrees by its height using post order traversal, and then to work on each gro
zestypanda
NORMAL
2017-07-30T17:22:29.758000+00:00
2017-07-30T17:22:29.758000+00:00
1,206
false
If two subtrees are the same, they have to have same height. The idea is to sort subtrees by its height using post order traversal, and then to work on each group with the same height. \n\nThe run time is O(n^2), the same as the string serialization solution. The analysis is as below. It takes O(n) time to sort subtree...
6
0
[]
2