Top K Frequent Elements (LeetCode 347) | Neetcode 5/ 150 | Bharath Chandra (తెలుగు)
ฝัง
- เผยแพร่เมื่อ 7 ส.ค. 2024
- Hello guys, cheers to another piece of learning. Today I talked about the "Top K Frequent Elements" problem which is the first in Neetcode 150 list. It is one of the most asked questions in interviews and has some interesting ways to solve it.
In the above video, I showed all the different logics with which the problem can be solved and also the codes to those logics in Python. Let me know if you got a hold of the logic?
Link to Hashsets and Hashmaps video - • Hashsets and HashMaps ...
Link to the problem - leetcode.com/problems/top-k-f...
Link to Java, C++ solution - leetcode.com/problems/top-k-f...
Link to Python Solution - leetcode.com/problems/top-k-f...
Link to Neetcode 150 - neetcode.io/practice=
Regular updates from me on Discord, Insta and Telegram. I post job notifications of telegram and discord
Insta - / bharathh_chandraa
Telegram - t.me/thebharathchandra
Discord - / discord
00:00 - Introduction and Problem Statement
01:51 - HashMap step
07:15 - Approach 1 with intuition
13:57 - Approach 2 with intution
22:49 - Approach 2 example
34:46 - Pseudocode
38:40 - Code and Conclusion
Excited For Daily Two Problems 🤞💥
So am I Manjith! Brace yourselves🙌🏻
Anna nice explanation with real time examples. hope anni sums lo ila real time examples use cheyali ani korukuntunna🤩
class Solution(object):
def topKFrequent(self, nums, k):
hashMap={}
for i in nums:
if i in hashMap:
hashMap[i] = hashMap[i]+1
else:
hashMap[i] = 1
l=[]
for i in range(k):
max_key = max(hashMap, key=hashMap.get)
l.append(max_key)
del hashMap[max_key]
return l
before staring the video
Bro code Java lo rayyandi
Bro expalination peaks but code tho step by step explain cheyy 🙏
niceee🎉
Nice anna
Thanks anna
5/150 ✅️
Let's goooooo. Solved it using sort
Another feather in your hat now!
python lone continue cheyyi anna , itss looks like psuedo code , and pyhton lo cheppe vallu chala thakkuva unnaru
lokesh anna,something is missing,ee video ki previous videos ki mundhu videos laga ney cheyandi anna better ga artham avuthundhi. meru em worry avvakandi viewers ni memu thisukoni vastham.
but ee video little bit tricky to understand
bro try to minimize the length of video bcz seeing long video can be bored or not intrested to watch end overall nice explanation about every possible example thanks bro
Sure Bharath! Keep Coding
linkedin link petttaledhu🤔
Bro after frequency Calculate chesaka Hash Map ni sort (Based on values chesi) K keys ni return chesthe avvutundaa?
Yes, if your language supports sorting based on values.
Make a video on heaps in python
Ee playlist lo anni data structures paina problems osthay. Heaps problems solve chese mundhu concept discuss chesthanu
@@bharathh_chandraa ok bruh
Your videos are damn good.Thanks for helping us
Hi Bharath, C# doesn't have HashTable Sort by value. any other way we can do. By Value.
You have to create an array of pairs. And then sort based on values, most of the languages don’t allow sort by values.
Else use the countArray approach, it is more efficient
@@bharathh_chandraa Approach 2: Completed. All Test case passed. But in c# when using Hashtable every time i have to cast value.
Bro only 2 approaches kada.. 1) hashmap with sorting, 2) hashmap without sorting..
TImeline lo approach 2 and approach 3 undhi, is that a typo ?
Also approach 2 lo kuda you need to create a 2nd hash map right ? else how do you know the key if you just sort the values.
Thanks for pointing this out Ranjan. 2 approaches ee unnay typo adhi.
Sorting approach lo you need an other array of pairs to maintain the keys and values together while sorting