Skip to content
Learn Netverks
Company prep Just Eat Takeaway.com
Junior (1–3 years) Coding / DSA Medium

How do you find the kth largest element efficiently?

Reported in Just Eat Takeaway.com European engineering loops. Heap and selection strategy question with multiple valid approaches.

Role
Data Engineer
Location
Barcelona, Spain

Context for Just Eat Takeaway.com candidates:

Find the kth largest number in an unsorted array where duplicates may exist.

Try answering aloud first

Cover trade-offs, structure, and a concrete example before revealing the baseline response.

Spoiler-free prep mode

How to frame this at Just Eat Takeaway.com: Connect your answer to measurable impact, clarity of thought, and trade-offs the team cares about. Below is a strong baseline response you can adapt with your own project examples.

Maintain a min-heap of size k. Push each number, and when heap size exceeds k, pop the smallest. At the end, heap top is the kth largest.

This gives O(n log k) time and O(k) space, which is practical when k is much smaller than n. Mention Quickselect as an average O(n) alternative but with worse-case concerns unless randomized.

Comments (0)

Share how this question came up in your loop, or add tips for others preparing.

Log in to comment on this question.