We can use maxHeap of pair by first computing freq of each elem in freq [26] array and then putting each pair in maxHeap.
@paragroy53593 жыл бұрын
I think we have to take the hash map bcz the character could be uppercase ,lowercase as well as it could be a digit.
@amitmandal584210 ай бұрын
Nice explanation..
@anuragsandhu95902 жыл бұрын
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-rn2tq4 жыл бұрын
Why we use lambda function in key?
@rishidhawan93234 жыл бұрын
string frequencySort(string s) { int freq[256]= {0}; string res; priority_queue maxHeap; for (int i=0; i
@rishidhawan93234 жыл бұрын
Using maxHeap
@aiyanshahid73744 жыл бұрын
why am i getting tle when my and your code is same