Most Frequent Element in a List

PYTHON coding challenge · Difficulty: easy · Topic: Dictionary and Counter · +50 XP

Given an integer list, find the element that appears most frequently and return it together with its count. If several elements share the same maximum frequency, return the smallest element among them.

This is a classic dictionary‑and‑Counter problem often used to test basic aggregation skills in data pipelines.

Example Input

`

arr = [1, 3, 2, 3, 4, 3, 2]

`

Expected Output

`

(3, 3)

`

Tie example

1 and 4 both appear twice; the smaller one wins:

`

arr = [4, 4, 1, 1, 3]

`

`

(1, 2)

`

What this PYTHON challenge teaches you

“Most Frequent Element in a List” is a easy-level PYTHON challenge focused on Dictionary and Counter. Working through it gives you hands-on practice with dictionary, counter, frequency — 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

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:

  1. 1 ≤ len(arr) ≤ 100000
  2. arr[i] ∈ [-10^9, 10^9]
  3. Return a tuple (element, frequency)

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

Helpful resources

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 Dictionary and Counter.

Solve this challenge free on PySpark.in