nums in the order of their first appearance. Each value appears exactly once in the result.Distinct Values
L2 Easy Arrays & Hashing
Concept
Combining a
Set for "seen before" checks with an array for ordering lets you deduplicate while preserving first-appearance order.Return the distinct integers of
Examples
▸ nums = [3, 1, 3, 2, 1]
→ [3, 1, 2]
▸ nums = []
→ []
▸ nums = [7]
→ [7]
Progressive Hints
Hint 1 · Nudge
You want first-appearance order, with repeats silently dropped.
Hint 2 · Plan
Keep a set of seen values and an empty result array. For each number, if it isn't already in the set, add it to both the set and the result. Return the result.
Hint 3 · Approach
seen = empty set; result = []. For each n: if n isn't in seen, add n to seen and append n to result. Return result.
All hints are out. Take a breath and give it a shot.
Output
// Run your code to see the output here.