EasyNo. 0619

Biggest Single Number — LeetCode 619 Python Solution

Topics
Database
Reading time
2 min

The problem

A single number is a value that appears exactly once in the table. Report the largest single number, or null when every value appears more than once. The MyNumbers table has one row per value and may contain duplicates: num (int).

Example

Example
MyNumbers table:

| num |
| --- |
| 12  |
| 7   |
| 12  |
| 30  |
| 4   |

Result:

| num |
| --- |
| 30  |

The values 7, 30 and 4 each appear once while 12 appears twice, so the largest single number is 30; had every value been repeated the answer would be null.

Python solution

PythonSolution
import pandas as pd

def biggest_single_number(my_numbers: pd.DataFrame) -> pd.DataFrame:
    counts = my_numbers['num'].value_counts()
    singles = counts[counts == 1]
    if singles.empty:
        return pd.DataFrame({'num': [None]})
    return pd.DataFrame({'num': [int(singles.index.max())]})

Complexity

Time
O(n log n)(typical)
Space · auxiliary
O(n)

Related problems

Related problems
No.ProblemDifficulty
0620Not Boring MoviesEasy
0626Exchange SeatsMedium
0627Swap Sex of EmployeesEasy
0610Triangle JudgementEasy
0175Combine Two TablesEasy
0176Second Highest SalaryMedium

Frequently asked questions

How hard is LeetCode 619. Biggest Single Number?

LeetCode 619. Biggest Single Number is rated Easy on LeetCode.

What topics does LeetCode 619. Biggest Single Number cover?

LeetCode 619. Biggest Single Number is tagged Database on LeetCode.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity, invisible to screen sharing.

Free to download. Check it runs on your machine, then pick a plan.