🚀 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
Solved LeetCode #49 with character-count tuple, faster for long words
More Relevant Posts
-
🚀 Day-77 of #100DaysOfCodeChallenge Today’s problem: Delete Nodes From Linked List Present in Array (LeetCode 3217) 💻 Working with linked lists always reminds me that sometimes in code — and in life — you have to remove what’s not needed to keep things moving efficiently ✂️ This challenge was about filtering out nodes whose values existed in a given array — a perfect mix of logic, pointer manipulation, and careful iteration 🔁 ✨ What I learned today: Efficiently handling deletions in a linked list without breaking the chain Using hash sets to make lookups faster on LeetCode. The importance of clean and minimal traversal logic Some problems aren’t just about syntax — they’re about clarity of thought 🧠 Another green check ✅ Another step closer to consistency 💪 #100DaysOfCode #LeetCode #ProblemSolving #CodingJourney #DataStructures #Algorithms #LinkedList #DeveloperLife #CodeEveryday #JavaDeveloper #TechJourney
To view or add a comment, sign in
-
-
💻 Day 47 of #50DaysOfLeetCode Challenge 🚀 Problem: Binary Tree Maximum Path Sum (Leetcode 124) The goal was to find the maximum path sum in a binary tree — where the path can start and end at any node, not just the root. 🌲 🧠 Approach: I solved it using postorder traversal (Left → Right → Root). At every node, I calculated: 1️⃣ bothpaths → path passing through root (left + right + root) 2️⃣ bestpath → best path going downward from root (max of left or right + root) 3️⃣ onlyroot → when only the root node is part of the path At each step, I updated a global maxsum with the best of these three values. This way, every node contributed the maximum possible sum considering all cases. 🧩 Key Takeaway: 👉 Always think in terms of "What value should I return to parent?" vs "What value should I update globally?" 👉 Binary tree recursion becomes intuitive once you separate these two thoughts.
To view or add a comment, sign in
-
-
#Day67 of my LeetCode Journey 🚀 Starting with Recursion problems ! 🧩 Question #8 – String to Integer (atoi) (Medium) Brute Force Approach: 1) Convert the string manually step-by-step remove whitespaces, handle signs, read digits, and clamp values. 2) Check for invalid inputs and handle edge cases like overflow/underflow explicitly. 3) Use iterative parsing to process characters sequentially. - Time Complexity: O(N) - Space Complexity: O(1) Optimal (Recursive) Approach: 1) Use recursion to simplify the parsing process each helper function handles one part (like skipping spaces, checking sign, removing zeros, or reading digits). 2) Extract digits recursively until a non-numeric character appears. 3) Convert digits to an integer and clamp it within the 32-bit signed range. - Time Complexity: O(N) - Space Complexity: O(N) (due to recursive calls) ✨ That’s it for Day 67. The journey continues — see you on Day 68. Happy coding! 🚀 #Day67 #LeetCodeJourney #LeetCode #Recursion #String #Atoi #Python #DSA #CodingPrep
To view or add a comment, sign in
-
-
🚀Day 77 of #120_Days_leetCode Challenge ! LeetCode Problem: Find and Replace Pattern Today’s problem was all about pattern matching with bijective mappings — where we find words that match a given pattern by establishing a one-to-one relationship between letters. 🧩 Problem Summary: Given a list of words and a string pattern, return all words that match the pattern. A word matches if you can permute letters such that each letter in the pattern maps uniquely to a letter in the word. 📘 Example: Input: words = ["abc","deq","mee","aqq","dkd","ccc"], pattern = "abb" Output: ["mee","aqq"] 💡 Intuition: To verify a match, we need to ensure: Each character in the pattern maps to only one unique letter in the word. No two pattern characters map to the same word character. This makes it a bijection problem — a perfect use case for hash maps. 🧠 Key Takeaways: Used two hash maps to maintain bijective character mapping. Achieved O(n * k) time complexity, where n = number of words and k = word length. Great practice for mastering string and hashmap-based logic problems. ✨ Every such problem reinforces how powerful simple mapping logic can be when applied thoughtfully. #LeetCode #ProblemSolving #CodingChallenge #DataStructures #Algorithms #ProgrammingJourney
To view or add a comment, sign in
-
-
🚀 Day 5 of my #LeetCodeChallenge Today’s problem: Search Insert Position (LeetCode #35) Category: 🧩 Array / Binary Search 💡 Problem Statement: Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be inserted in order. Example: Input: nums = [1,3,5,6], target = 5 Output: 2 ➡️ Since 5 is found at index 2. Input: nums = [1,3,5,6], target = 2 Output: 1 ➡️ It would be inserted before 3. 🧠 Approach: Used Binary Search for O(log n) efficiency. Checked if target exists, otherwise found the correct insertion index.
To view or add a comment, sign in
-
-
🚀 Day 125 of #LeetCode Challenge! Problem: Binary Tree Preorder Traversal 💡 My Approach: The goal is to perform a preorder traversal of a binary tree — visiting nodes in the order: Root → Left → Right Here’s the step-by-step logic: Start from the root node. Visit (record) the root value first. Recursively traverse the left subtree, then the right subtree. Store values in a vector as you go. ✨ Example Input: [1, null, 2, 3] Output: [1, 2, 3] 🧠 Key Idea Preorder traversal is useful when you need to copy or serialize a tree — it captures the structure starting from the root. ⏱ Complexity TypeValueTimeO(N) — each node visited onceSpaceO(H) — recursion stack (H = height of tree) 📎 GitHub Link: https://lnkd.in/gZ6GeXzm #LeetCode #BinaryTree #PreorderTraversal #Recursion #DSA #C++ #ProblemSolving #CodingChallenge #Day125
To view or add a comment, sign in
-
-
🔍 Day 66 of #100DaysOfCode 🔍 🔹 Problem: Binary Search – LeetCode ✨ Approach: Implemented an iterative binary search to efficiently locate the target element within a sorted array. By halving the search range each time — adjusting low and high around the mid-point — the algorithm achieves blazing-fast lookups! ⚡ 📊 Complexity Analysis: Time Complexity: O(log n) — array size halves with each iteration Space Complexity: O(1) — constant extra space ✅ Runtime: 0 ms (Beats 100.00%) ✅ Memory: 46.02 MB 🔑 Key Insight: Binary Search is proof that efficiency isn’t about doing more — it’s about eliminating what’s unnecessary. 🚀 #LeetCode #100DaysOfCode #ProblemSolving #DSA #AlgorithmDesign #BinarySearch #LogicBuilding #Efficiency #ProgrammingChallenge #CodeJourney #CodingDaily
To view or add a comment, sign in
-
-
✅ Day 2/75 🌟 Today’s Progress 1️⃣Two Sum: LeetCode Easy Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. 🔹 Approaches: 1️⃣ Brute Force Check every pair by using nested loops and return indices if sum matches. Time: O(N*N) | Space: O(1) 2️⃣ Better Approach – Sorting + Two Pointers Store (value, index) pairs -> Sort ->Use two pointers to find target sum. Time: O(N log N) | Space: O(N) (Keep original indices before sorting ✅) 3️⃣ Optimal – Hash Map Store number -> index. For each element, check if (target - nums[i]) exists in map. Time: O(N) | Space: O(N) 2️⃣ Group Anagrams: LeetCode Medium Given an array of strings strs, group the anagrams together. You can return the answer in any order. 🔹Approaches: 1️⃣ Sorting + Hashing Sort each word so anagrams look the same. Used that sorted version as a key in a HashMap to group them. Sorting helps identify anagrams. HashMap helps group them quickly. Time: O(N × K log K) 2️⃣ Character Frequency Hashing Count the frequency of each character in the string and make that frequency the key. Words with the same character count will form one group. Time: O(N × K) Space: O(N × K) Small steps daily. On to Day 3 tomorrow. 💪✨ #NeetCode #Blind75 #DSA #LeetCode #CodingChallenge #ProblemSolving
To view or add a comment, sign in
-
🌳 Day 48 of #50DaysOfLeetCode Challenge 💡 Problem: Sum Root to Leaf Numbers (LeetCode 129) Given the root of a binary tree, each root-to-leaf path represents a number. We need to find the total sum of all these numbers. 🧠 Concepts Used: Recursion Depth-first traversal (DFS) Carrying state (currsum) through recursive calls 🧩 Approach: At each node, multiply the current sum by 10 and add the node’s value. If it’s a leaf node → return the number formed so far. Otherwise, recursively compute sums for left and right subtrees and return their total.
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development