Validate Unique User IDs
PYTHON coding challenge · Difficulty: easy · Topic: Data Validation Pipeline · +50 XP
Problem
Function Signature
------------------
def validate_unique_ids(user_ids: list) -> dict:
Problem
-------
Given a list of user IDs, validate them
and return a report.
Return a dictionary with:
"valid" → list of valid IDs
"duplicates" → list of IDs appearing 2+
"invalid" → list of IDs that are not
positive integers
Rules:
• Valid: positive integer (>0), unique
• Duplicate: appears more than once
• Invalid: negative, zero, non-integer,
or non-numeric string
Example 1
---------
Input:
[101, 102, 101, -5, "abc", 103, 0]
Output:
{
"valid": [102, 103],
"duplicates": [101],
"invalid": [-5, "abc", 0]
}
Example 2
---------
Input: [1, 2, 3, 4, 5]
Output:
{
"valid": [1, 2, 3, 4, 5],
"duplicates": [],
"invalid": []
}
Example 3 (Edge case)
---------------------
Input: []
Output: {"valid":[], "duplicates":[],"invalid":[]}
Constraints
-----------
• 0 <= len(user_ids) <= 100,000
• Each element can be any Python type
• Return lists sorted in ascending order
Example Input
These calls are already in the editor below.
`python
validate_unique_ids([101, 102, 103, 104, 105]) # all distinct
validate_unique_ids([101, 102, 101, 103]) # 101 appears twice
validate_unique_ids([]) # nothing to clash
`
Expected Output
`
True
`
Explanation
One line of output per call, in order. The first list has no repeats, so True. The second repeats 101, so False. The third is empty — there is no duplicate in it, so it is trivially unique and prints True. That empty case is the one worth checking: len(ids) == len(set(ids)) handles it correctly, but an approach that compares neighbours after sorting can trip on it.
Notes
- Print the result — the grader reads standard output
- Do not redefine the input; it is provided for you
What this PYTHON challenge teaches you
“Validate Unique User IDs” is a easy-level PYTHON challenge focused on Data Validation Pipeline. Working through it gives you hands-on practice with hash set, uniqueness, data integrity — the kind of transformation you are asked to write in real data engineering work and in technical interviews. You can solve it directly in the browser: the dataset is pre-loaded, so you write the query or DataFrame code, run it, and compare your output against the expected result immediately.
Concepts covered
- hash set
- uniqueness
- data integrity
How to approach it
If you get stuck, work through these steps in order before looking at a full solution — each one narrows the problem down:
- Your result should return: a dictionary with:.
- Compare your output to the Expected Output — the columns, values and row order must match exactly.
Where this comes up
Variations of this problem have been reported in interviews at Google, Paytm, PhonePe. Interviewers use it to check whether you can express the logic cleanly and reason about correctness on edge cases such as ties, nulls and empty groups.
How to practise it on PySpark.in
Open the challenge, write your Python code in the editor and press Run to execute it against the sample dataset. Submitting checks your output against every test case, including hidden ones, so you find out straight away whether your logic holds up. You can retry as often as you like, and each solved challenge adds to your XP.
Related PYTHON challenges
- Detect Anomalies in Transaction Batches
- Word Frequency Counter
- Extract Error Codes from Log Strings
- Sum of Values by Key
- Flatten Nested JSON Structure
- Top K Frequent Elements in a Stream
Frequently asked questions
Do I need to install Spark or a database to solve this?
No. The PYTHON environment runs in your browser with the sample data already loaded, so there is nothing to install or configure.
Is this challenge free?
Yes - the problem, the sample dataset, the hints and unlimited test runs are free.
What level is it?
It is rated easy and covers Data Validation Pipeline.