Off-by-one on range boundaries
Wrong move: Loop endpoints miss first/last candidate.
Usually fails on: Fails on minimal arrays and exact-boundary answers.
Fix: Re-derive loops from inclusive/exclusive ranges before coding.
Build confidence with an intuition-first walkthrough focused on core interview patterns fundamentals.
Table: Person
+-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | email | varchar | +-------------+---------+ id is the primary key (column with unique values) for this table. Each row of this table contains an email. The emails will not contain uppercase letters.
Write a solution to report all the duplicate emails. Note that it's guaranteed that the email field is not NULL.
Return the result table in any order.
The result format is in the following example.
Example 1:
Input: Person table: +----+---------+ | id | email | +----+---------+ | 1 | a@b.com | | 2 | c@d.com | | 3 | a@b.com | +----+---------+ Output: +---------+ | Email | +---------+ | a@b.com | +---------+ Explanation: a@b.com is repeated two times.
Problem summary: Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | email | varchar | +-------------+---------+ id is the primary key (column with unique values) for this table. Each row of this table contains an email. The emails will not contain uppercase letters. Write a solution to report all the duplicate emails. Note that it's guaranteed that the email field is not NULL. Return the result table in any order. The result format is in the following example.
Start with the most direct exhaustive search. That gives a correctness anchor before optimizing.
Pattern signal: General problem-solving
{"headers": {"Person": ["id", "email"]}, "rows": {"Person": [[1, "a@b.com"], [2, "c@d.com"], [3, "a@b.com"]]}}Source-backed implementations are provided below for direct study and interview prep.
// Accepted solution for LeetCode #182: Duplicate Emails
// Auto-generated Java example from py.
class Solution {
public void exampleSolution() {
}
}
// Reference (py):
// # Accepted solution for LeetCode #182: Duplicate Emails
// import pandas as pd
//
//
// def duplicate_emails(person: pd.DataFrame) -> pd.DataFrame:
// results = pd.DataFrame()
//
// results = person.loc[person.duplicated(subset=["email"]), ["email"]]
//
// return results.drop_duplicates()
// Accepted solution for LeetCode #182: Duplicate Emails
// Auto-generated Go example from py.
func exampleSolution() {
}
// Reference (py):
// # Accepted solution for LeetCode #182: Duplicate Emails
// import pandas as pd
//
//
// def duplicate_emails(person: pd.DataFrame) -> pd.DataFrame:
// results = pd.DataFrame()
//
// results = person.loc[person.duplicated(subset=["email"]), ["email"]]
//
// return results.drop_duplicates()
# Accepted solution for LeetCode #182: Duplicate Emails
import pandas as pd
def duplicate_emails(person: pd.DataFrame) -> pd.DataFrame:
results = pd.DataFrame()
results = person.loc[person.duplicated(subset=["email"]), ["email"]]
return results.drop_duplicates()
// Accepted solution for LeetCode #182: Duplicate Emails
// Rust example auto-generated from py reference.
// Replace the signature and local types with the exact LeetCode harness for this problem.
impl Solution {
pub fn rust_example() {
// Port the logic from the reference block below.
}
}
// Reference (py):
// # Accepted solution for LeetCode #182: Duplicate Emails
// import pandas as pd
//
//
// def duplicate_emails(person: pd.DataFrame) -> pd.DataFrame:
// results = pd.DataFrame()
//
// results = person.loc[person.duplicated(subset=["email"]), ["email"]]
//
// return results.drop_duplicates()
// Accepted solution for LeetCode #182: Duplicate Emails
// Auto-generated TypeScript example from py.
function exampleSolution(): void {
}
// Reference (py):
// # Accepted solution for LeetCode #182: Duplicate Emails
// import pandas as pd
//
//
// def duplicate_emails(person: pd.DataFrame) -> pd.DataFrame:
// results = pd.DataFrame()
//
// results = person.loc[person.duplicated(subset=["email"]), ["email"]]
//
// return results.drop_duplicates()
Use this to step through a reusable interview workflow for this problem.
Two nested loops check every pair or subarray. The outer loop fixes a starting point, the inner loop extends or searches. For n elements this gives up to n²/2 operations. No extra space, but the quadratic time is prohibitive for large inputs.
Most array problems have an O(n²) brute force (nested loops) and an O(n) optimal (single pass with clever state tracking). The key is identifying what information to maintain as you scan: a running max, a prefix sum, a hash map of seen values, or two pointers.
Review these before coding to avoid predictable interview regressions.
Wrong move: Loop endpoints miss first/last candidate.
Usually fails on: Fails on minimal arrays and exact-boundary answers.
Fix: Re-derive loops from inclusive/exclusive ranges before coding.