Skip to main content
Back to problems
Leetcode
Medium
Arrays
Strings
Hash Maps
Article Views I

Find the authors who have viewed at least one of their own articles and return their IDs in ascending order.

Acceptance 100%
Problem Statement

Problem

You are given a table of article view records. Each record contains an author and the viewer of an article.

An author is said to have viewed their own article if there exists at least one record where the author_id and viewer_id are the same.

Return the list of authors who have done this, sorted in ascending order by id.

Notes

  • An author should appear only once in the result, even if they viewed their own article multiple times.
  • The result should contain the authors' IDs only.

Intuition

This is a simple filtering and deduplication task: keep only rows where the two IDs match, then remove duplicates and sort.

Input Format

The input is a collection of article view records. Each record has at least:

  • author_id
  • viewer_id

For example, the data may be represented as a list of objects/rows or as a database table.

Output Format

Return the unique author_id values for rows where author_id = viewer_id, sorted in ascending order.

Constraints

  • Each record contains integer IDs.
  • The result must not contain duplicates.
  • If no author viewed their own article, return an empty list.
Examples
Sample cases returned by the problem API.

Example 1

Input

views = [[1,3],[2,2],[3,1],[3,3],[4,5]]

Output

[2,3]

Explanation

Authors 2 and 3 appear in rows where the author viewed their own article.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.