Find the Second Largest Number

PYTHON coding challenge · Difficulty: easy · Topic: Basics · +50 XP

Problem

Given the list nums (at least two distinct values), print the second largest distinct value.

Example Input

The data below is already defined — do not redefine it.

`python

nums = [40, 10, 55, 25, 55, 30]

`

Expected Output

`

40

`

Explanation

Sort the DISTINCT values, not the raw list. Here 55 appears twice, so a naive "second element after sorting descending" returns 55 again — the duplicate, not the second largest. Removing duplicates first gives 55, 40, 30, 25, 10, and the answer is 40.

Notes

What this PYTHON challenge teaches you

“Find the Second Largest Number” is a easy-level PYTHON challenge focused on Basics. Working through it gives you hands-on practice with beginner — 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. Duplicates matter: with [5, 5, 3] the second largest is 3, not 5.
  2. set() removes duplicates, sorted() orders what is left, and [-2] is the second from the end.

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

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 Basics.

Solve this challenge free on PySpark.in