Biggest Single Number - Problem
You are given a table MyNumbers that contains integers. Some numbers may appear multiple times while others appear only once.
Goal: Find the largest number that appears exactly once in the table. If no such number exists, return null.
Table Structure:
num(int): An integer value
Note: The table has no primary key, so duplicate values are allowed.
Table Schema
MyNumbers
| Column Name | Type | Description |
|---|---|---|
num
|
int | Integer value that may appear multiple times |
Primary Key: none
Note: Table allows duplicates, no primary key defined
Input & Output
Example 1 — Multiple Singles Exist
Input Table:
| num |
|---|
| 8 |
| 3 |
| 5 |
| 4 |
| 3 |
| 6 |
Output:
| num |
|---|
| 8 |
💡 Note:
Numbers 8, 5, 4, and 6 appear exactly once, while 3 appears twice. The largest single number is 8.
Example 2 — All Numbers Repeat
Input Table:
| num |
|---|
| 1 |
| 1 |
| 2 |
| 2 |
Output:
| num |
|---|
💡 Note:
Both numbers 1 and 2 appear twice. Since no number appears exactly once, the result is null.
Example 3 — Single Number Only
Input Table:
| num |
|---|
| 10 |
Output:
| num |
|---|
| 10 |
💡 Note:
Only one number exists and it appears once, so 10 is the biggest single number.
Constraints
-
1 ≤ MyNumbers.length ≤ 1000 -
-1000 ≤ num ≤ 1000
Visualization
Tap to expand
Understanding the Visualization
1
Input
MyNumbers table with duplicates
2
Filter
GROUP BY + HAVING for singles
3
MAX
Find largest single number
Key Takeaway
🎯 Key Insight: Use GROUP BY with HAVING to filter for single occurrences, then MAX to find the largest
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code