Kth Largest Element in an Array || Leetcode 215 || 2 Variant Questions Big Tech Actually Asks

preview_player
Показать описание
Discover the actual variants Meta asks on Leetcode problem 215: Kth Largest Element in an Array.

Timestamps:
00:00 Leetcode Explanation
11:22 Leetcode Coding
12:19 Variant #1 Explanation (Kth+1 Largest)
15:35 Variant #1 Coding (Kth+1 Largest)
16:08 Variant #2 Explanation (Kth Smallest)
20:12 Variant #2 Coding (Kth Smallest)

Follow us on social media:

GitHub:

More Context:
FAANG, mid-sized companies, and startups are asking more LeetCode-style puzzle questions every day, making it harder to stand out as the competition grows. With an increasing number of new graduates entering the software market and tech companies laying off developers while overworking those who remain, it’s a tough landscape. Take Meta, for example: they expect 2-3 months of intense study time, only to likely ghost you afterward. But this doesn’t mean we should be unprepared.

While LeetCode is a valuable learning resource, many developers focus too much on rote memorization. Others find themselves stuck in a vicious cycle, where they don’t study as efficiently as they could because they’re juggling multiple responsibilities. They have full-time jobs, personal commitments, or other obligations that limit the time they can dedicate to solving problems. It’s a grind. Unfortunately, most companies introduce their own twists or "variants" of common problems (e.g., 6-sum instead of 2-sum), which throw candidates off. Rephrasings of problems and follow-up questions are also common, so recognizing these variations and curveballs is crucial.

For those who don’t have the time to revisit LeetCode problems multiple times to solidify concepts, this channel covers the most frequently asked variants, rephrasings, and follow-ups. If you've seen these before, you’ll have a significant edge over your competitors. Remember, time pressure — especially at Meta — is intense, so speed is essential. Even with thorough preparation, interviewers may be unpredictable, but knowing the variants beforehand can drastically increase your chances of success.

Take LeetCode 215, Kth Largest Element in an Array, which is one of Meta’s most frequently asked questions (top 5 as of writing). Meta often sticks to the original problem. Variants - however - do exist, and with thousands of interviewers, it's hard to predict them all. We cover two key variants: one, what if you had to return the Kth+1 largest element? Two, what if you had to return the Kth smallest element?

We also walk through variants in mock interviews. Using the exact platform (CoderPad) that Meta uses, you’ll get familiar with the UI, settings, and overall experience. This is a 1-on-1 simulation of how Meta conducts and facilitates their interviews, so the goal is to avoid wasting time on the tool itself. Once again, time limits at Meta are a huge factor, so speed is critical.

That said, even with perfect preparation, interviewers might not always be in a good mood or may judge unfairly. The interview process has its power dynamics, but with insider knowledge, you’ll have done as much as you can on your end to secure a Strong Hire decision.
Рекомендации по теме
Комментарии
Автор

Hey Minh, I got a variant of this (K closest points to the origin) in my Meta phone screen and somehow passed. Binge watched all your videos, thanks so much for your hard work putting this together! Do you recommend re-reviewing everything ahead of my onsite or doing any additional prep/problems to be ready?

I'm weaker in a few areas like recursion/backtracking, sliding window but stronger in others like graphs so was thinking to maybe focus on my weaknesses in addition to re-reviewing the top 50 problems.

fma
Автор

Really liked your approach, very subtle and concise

ExodusIsLive
Автор

I really love how you extend to its variants, and great explanation btw! Keep it up!

yashpreetbathla
Автор

Thanks buddy, for clearing up the mind, i was really thinking how would i code quick select in 15 mins with explanation.

yashpreetbathla
Автор

Done. also with variants. Under Heaps sec

adarshmv
Автор

Hi Minh. Love the video as always. Does Meta ever expect you to solve this question (or other variants, top K most/least frequent elements) using quick select?

seaDeeTea
Автор

hey minmer, do you think the quick select algorithm solution can be asked?

AnubhutiSrivastava-qcrt
Автор

Can I use Quickselect with auxiliary Java arraylists (or vector in C++) to store the numbers needed for next recursion, rather than using 2 pointers to specify the range?
I mean if we use 2 pointers to indicate current range in the original array, which means to swap elements in place during the quickselect process while doing recursion. This is optimal but the swap is complex and error prone during a 15 min interview. The auxiliary arraylist approach is to create left, mid, right 3 lists which contains elements that are smaller, equal and larger. This is much easier to code during an interview. However, the downside is this is not in-place and the space complexity is not O(1).
But given that quickselect usually needs recursion, technically speaking, recursion itself takes space as well. So I am wondering if I can do quickselect with arraylist approach during an interview

Hikaru-uk
Автор

I think we can also use a max-heap instead, heapify operation would cost O(n), then k pop operations (each costing log n) to find the k-th largest element. That would sum up to O(n + k log n) TC, right?

rafaelladeira
Автор

I was asked this question in phone screen with Meta few years ago and the interviewer expclitly asked quick select after I produced min heap approach

qwer
Автор

I heard that Meta asks quick sort when compared to min heap...

Abhishek-zy-xb
Автор

There is another variant, they want to return the index of the kth largest element

codewiz
Автор

one thing that completely confuses me is I heard that in Python heapify() method that creates a heap from array has a O(n) time complexity, then you need to remove k values to get k largest. Such solution would require more space, I guess.

But I don't think we have a O(n) heapify method in Java or C++

NormalHuman
Автор

Hi could you cover valid word abbreviation and the variant where word can have numbers such as h5ello, h8o is valid. And a12b, a12b as well. It's a popular one

albertvu
Автор

For Variant 2 I'd much rather just do k = n - k, rather than a max heap, just because a max heap does not exist in python lol (you have to make a minheap and negate all numbers instead)

TheMereth
Автор

It could be also solved with binary search, right? But I am surprised that binary search is not even mentioned in the editorial. Using heap also feels like sorting to me because heapsort is based on this. But according to the description, feels like binary search fits more.

rawnaksarker
join shbcf.ru