Solved LeetCode #49 with character-count tuple, faster for long words

🚀 Day 12 — LeetCode #49: Group Anagrams I solved #LeetCode49 using a hash map with a character-count key (O(N·K) time). Instead of sorting each string, I used a fixed 26-length tuple of character counts as the dictionary key — faster when strings get long. 💡 Solution idea: For each word create a 26-entry count tuple and group words with the same tuple. 🧩 Challenge for you: Which approach would you pick and why? A — Sort each string (simple & intuitive) B — Character-count tuple (O(N·K), great for long words) C — Other (prime-hash, multiset, language-specific tricks) — share below! Drop your choice in the comments and paste your implementation (or a one-liner)! I'll feature interesting takes and explain trade-offs. #100DaysOfCode #DataStructures #Algorithms #C++ #LeetCode

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories