Sort Characters by Frequency | LeetCode 451 | C++, Java, Python | May LeetCoding Day 22

  Рет қаралды 8,812

Knowledge Center

Knowledge Center

Күн бұрын

Пікірлер: 11
@vaibhavmalik6490
@vaibhavmalik6490 4 жыл бұрын
We can use maxHeap of pair by first computing freq of each elem in freq [26] array and then putting each pair in maxHeap.
@paragroy5359
@paragroy5359 3 жыл бұрын
I think we have to take the hash map bcz the character could be uppercase ,lowercase as well as it could be a digit.
@amitmandal5842
@amitmandal5842 10 ай бұрын
Nice explanation..
@anuragsandhu9590
@anuragsandhu9590 2 жыл бұрын
Concept Used: All numeric keys in object in javascript are sorted in ascending order | O(n) time complexity | O(26) space complexity var frequencySort = function (s) { const obj = {}; for (let index = 0; index < s.length; index++) { if (!obj[s[index]]) { obj[s[index]] = 1; } else { obj[s[index]] += 1; } } const convertedObj = {}; for (const key in obj) { if (convertedObj[obj[key]]) { convertedObj[obj[key]][key] = key.repeat(obj[key]); } else { convertedObj[obj[key]] = { [key]: key.repeat(obj[key]) }; } } const keys = Object.keys(convertedObj); let str = ''; for (let index = keys.length - 1; index >= 0; index--) { for (const key in convertedObj[keys[index]]) { str += convertedObj[keys[index]][key]; } } return str; };
@TheArbaaz-rn2tq
@TheArbaaz-rn2tq 4 жыл бұрын
Why we use lambda function in key?
@rishidhawan9323
@rishidhawan9323 4 жыл бұрын
string frequencySort(string s) { int freq[256]= {0}; string res; priority_queue maxHeap; for (int i=0; i
@rishidhawan9323
@rishidhawan9323 4 жыл бұрын
Using maxHeap
@aiyanshahid7374
@aiyanshahid7374 4 жыл бұрын
why am i getting tle when my and your code is same
@KnowledgeCenter
@KnowledgeCenter 4 жыл бұрын
Can you paste your code here?
@Star_Bawa9
@Star_Bawa9 2 жыл бұрын
I have not understood the Collections . sort part
ТВОИ РОДИТЕЛИ И ЧЕЛОВЕК ПАУК 😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 4,9 МЛН
Twin Telepathy Challenge!
00:23
Stokes Twins
Рет қаралды 65 МЛН
Sort Characters By Frequency - Leetcode 451 - Python
10:57
NeetCodeIO
Рет қаралды 18 М.
Edit Distance | Dynamic Programming | LeetCode 72 | C++, Java, Python
27:22
Sort Characters By Frequency | Leetcode #451
7:15
Techdose
Рет қаралды 47 М.
Sort Characters By Frequency | Sorting | Lambda | Leetcode 451
17:24
codestorywithMIK
Рет қаралды 9 М.
How I Failed the Google Coding Interview (and lessons I learned)
14:24
LeetCode 451 Solution in Hindi | Sort Characters By Frequency Solution
14:42
Engineering Digest
Рет қаралды 3,6 М.
Stream of Characters | LeetCode 1032 | C++, Java, Python
26:25
Knowledge Center
Рет қаралды 4,9 М.
ТВОИ РОДИТЕЛИ И ЧЕЛОВЕК ПАУК 😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 4,9 МЛН