LeetCode Courses 3866. First Unique Even Element
LeetCode

3866. First Unique Even Element

We iterate from a manual counts dict through `Counter` to a one-pass dict-as-ordered-set, then land on Counter filtered by a generator. Readable over clever when the complexity is the same.

1 chapter Beginner Written walk-through Updated 29 May 2026 Phil · @FirnoxGames
Free

Free for everyone. No account needed.

Start reading →

What you'll learn

1 3866. First Unique Even Element 📖 9 min read

We iterate from a manual counts dict through `Counter` to a one-pass dict-as-ordered-set, then land on Counter filtered by a generator. Readable over clever when the complexity is the same.

In this chapter
  1. Problem
  2. Two-pass
  3. Counter
  4. Without revisiting nums
  5. Desired solution

Problem

You are given an integer array nums.

Return an integer denoting the first even integer (earliest by array index) that appears exactly once in nums. If no such integer exists, return -1.

An integer x is considered even if it is divisible by 2.

Included with this course
📖Written version of every chapter