TGViewer
Data Science Data Science @datascience_official · 566 subscribers
Post #241 52
1st Code

var majorityFrequencyGroup = function(s) {
const freqMap = new Map();
for (const char of s) {
freqMap.set(char, (freqMap.get(char) || 0) + 1);
}

const groups = new Map();
for (const [char, freq] of freqMap.entries()) {
if (!groups.has(freq)) groups.set(freq, []);
groups.get(freq).push(char);
}

let bestSize = -1, bestFreq = -1;
let bestGroup = [];
for (const [freq, chars] of groups.entries()) {
const groupSize = chars.length;
if (groupSize > bestSize || (groupSize === bestSize && freq > bestFreq)) {
bestSize = groupSize;
bestFreq = freq;
bestGroup = chars;
}
}

return bestGroup.join('');
};

Join👇

    @leetcode_cp
      @leetcode_cp
More from @datascience_official
  1. Oct 8, 2026INDIA'S BIGGEST SHOPPING SALE IS LIVE TOMORROW IS IT REALLY A DEAL🤡? THIS APP BUYHATKE TE…
  2. Oct 3, 2026𝗧𝗵𝗼𝘀𝗲 𝘄𝗵𝗼 𝘄𝗮𝗻𝘁 𝗿𝗲𝗳𝗲𝗿𝗿𝗮𝗹𝘀 𝗮𝗻𝗱 𝗝𝗼𝗯𝘀 𝗮𝗻𝗱 𝗜𝗻𝘁𝗲𝗿𝗻𝘀𝗵𝗶𝗽�…
  3. Sep 30, 2026❤️ Here is the list of highly recommended Telegram channels for your free learning ❤️ Get…
  4. Sep 27, 2026🚨 Earn Passive Money Easily 🚨 Since your device is already connected to the internet, yo…
  5. Sep 26, 2026Hackathon National Research & Innovation Challenge Season 3 📌APPLY LINK : https://bit.ly/…
  6. Sep 13, 2026A-Z of essential data science concepts A: Algorithm - A set of rules or instructions for s…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →