🚀 Day 44 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Find the Least Frequent Digit Problem Insight: Find the digit (0–9) that appears the least number of times in a given number. Approach: • Used a frequency array of size 10 to store digit counts • Extracted digits using modulo and division • Traversed the frequency array to find the minimum occurring digit • Returned the smallest digit in case of tie Time Complexity: • O(n) Space Complexity: • O(1) (fixed size array of 10) Key Learnings: • Arrays are more efficient than HashMap when range is limited • Digit extraction using % 10 is very useful in number problems • Keeping track of minimum efficiently avoids extra passes Takeaway: Simple logic + right data structure = clean and optimal solution #DSA #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving
Solved LeetCode Find the Least Frequent Digit in 100 Days of Code
More Relevant Posts
-
🚀 Day 43 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Sum of Unique Elements Problem Insight: Find elements in an array that appear exactly once and calculate their total sum. Approach: • Used a frequency array to count occurrences of each number • Traversed the array to build frequency • Added only those elements to sum whose frequency is exactly 1 Time Complexity: • O(n) Space Complexity: • O(1) (fixed size array used for constraints) Key Learnings: • Frequency array is faster than HashMap when range is fixed • Two-pass approach makes logic clear and simple • Always check constraints before choosing data structure Takeaway: Right data structure makes the solution simple and efficient 🚀 #DSA #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 15 of LeetCode Problem Solving Solved today’s problem — LeetCode #49: Group Anagrams 💻🔥 ✅ Approach: HashMap + Sorting ⚡ Time Complexity: O(n * k log k) 📊 Space Complexity: O(n * k) The task was to group strings that are anagrams of each other. 👉 I used a HashMap where: Key = sorted version of string Value = list of anagrams 💡 Key Idea: If two strings are anagrams, their sorted form will be the same. 👉 Core Logic: Convert string → char array Sort the array Use sorted string as key Store original string in map 💡 Key Learning: Transforming data (like sorting strings) can help in identifying patterns and grouping efficiently. Consistency is the key — learning something new every day 🚀 #Day15 #LeetCode #DSA #Java #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🔥 Day 60 / 100 – LeetCode Challenge ✅ Solved: 160. Intersection of Two Linked Lists Today’s problem was all about understanding pointer behavior and memory references in linked lists. 💡 Key Insight: Instead of comparing values, we compare node references. If two linked lists intersect, they will share the same tail nodes. 🚀 Approach Used (Optimal): Two pointers (pA, pB) Traverse both lists When one reaches the end, switch to the other list They eventually meet at the intersection node (or null) 🧠 Why it works: Both pointers travel equal distance → LengthA + LengthB, aligning perfectly without extra space. ⏱ Complexity: Time: O(m + n) Space: O(1) 💻 Result: ✔️ Accepted (41/41 test cases) ⚡ Runtime: 1 ms (Beats 99.94%) 📌 Takeaway: Sometimes the smartest solution is not about extra data structures, but about clever traversal. #Day60 #100DaysOfCode #LeetCode #Java #DSA #LinkedList #CodingJourney
To view or add a comment, sign in
-
-
Day 113 - LeetCode Journey Solved LeetCode 222 – Count Complete Tree Nodes ✅ This problem involves counting the total number of nodes in a complete binary tree, where all levels are fully filled except possibly the last, and nodes are as far left as possible. Approach: I implemented a recursive solution to count nodes. For each node, I recursively calculated the number of nodes in the left and right subtrees and added 1 for the current node. Although this solution works correctly, it follows a straightforward traversal approach and does not fully utilize the properties of a complete binary tree. A more optimized approach can reduce time complexity by comparing left and right subtree heights to detect perfect subtrees and compute their node count directly. Complexity Analysis: • Time Complexity: O(n) • Space Complexity: O(h), where h is the height of the tree (recursion stack) Key Takeaways: • Basic tree traversal (DFS) can solve counting problems effectively • Understanding tree properties can help in optimizing solutions further • Complete binary trees allow more efficient approaches than general trees All test cases passed successfully 🎯 #LeetCode #DSA #BinaryTree #Recursion #Java #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 76 — Slow & Fast Pointer (Find the Duplicate Number) Continuing the cycle detection pattern — today I applied slow‑fast pointers to an array problem where the values act as pointers to indices. 📌 Problem Solved: - LeetCode 287 – Find the Duplicate Number 🧠 Key Learnings: 1️⃣ The Problem Twist Given an array of length `n+1` containing integers from `1` to `n` (inclusive), with one duplicate. We must find the duplicate without modifying the array and using only O(1) extra space. 2️⃣ Why Slow‑Fast Pointer Works Here - Treat the array as a linked list where `i` points to `nums[i]`. - Because there’s a duplicate, two different indices point to the same value → a cycle exists in this implicit linked list. - The duplicate number is exactly the entry point of the cycle (same logic as LeetCode 142). 3️⃣ The Algorithm in Steps - Phase 1 (detect cycle): `slow = nums[slow]`, `fast = nums[nums[fast]]`. Wait for them to meet. - Phase 2 (find cycle start): Reset `slow = 0`, then move both one step at a time until they meet again. The meeting point is the duplicate. 4️⃣ Why Not Use Sorting or Hashing? - Sorting modifies the array (not allowed). - Hashing uses O(n) space (not allowed). - Slow‑fast pointer runs in O(n) time and O(1) space — perfect for the constraints. 💡 Takeaway: This problem beautifully demonstrates how the slow‑fast pattern transcends linked lists. Any structure where you can define a “next” function (here: `next(i) = nums[i]`) can be analyzed for cycles. Recognizing this abstraction is a superpower. No guilt about past breaks — just another pattern mastered, one day at a time. #DSA #SlowFastPointer #CycleDetection #FindDuplicateNumber #LeetCode #CodingJourney #Revision #Java #ProblemSolving #Consistency #GrowthMindset #TechCommunity #LearningInPublic
To view or add a comment, sign in
-
🚀 LeetCode Challenge 19/50 💡 Approach: Horizontal Scanning The sorting-based approach costs O(S log n). Instead, I used Horizontal Scanning — take the first string as the prefix and keep shrinking it until every string agrees. No sorting, no extra space! 🔍 Key Insight: → Start with strs[0] as the full prefix candidate → For each next string, shrink prefix from the right until it matches → If prefix becomes empty at any point → return "" → What's left is the longest common prefix! 📈 Complexity: ❌ Sort-based → O(S log n) Time ✅ Horizontal Scan → O(S) Time, O(1) Space where S = total characters across all strings The smartest solutions don't always need fancy data structures — sometimes a simple shrinking window does the job perfectly! 🪟 #LeetCode #DSA #StringManipulation #Java #ADA #PBL2 #LeetCodeChallenge #Day19of50 #CodingJourney #ComputerEngineering #AlgorithmDesign #LongestCommonPrefix
To view or add a comment, sign in
-
-
Day 34/50 🚀 — Score of a String Today’s problem was all about observing patterns in characters and keeping the approach simple. 🔹 Compared ASCII values of adjacent characters 🔹 Used absolute difference to calculate contribution 🔹 Built the result in a single pass (no extra space) Key insight: Sometimes you don’t need complex data structures—just a clean loop and understanding how characters behave as numbers. 💡 Simple logic, implemented cleanly, is often the most efficient solution. Performance: ⚡ Runtime: 1 ms (99%+) 📦 Memory: Efficient #Day34 #50DaysOfCode #Java #DSA #ProblemSolving
To view or add a comment, sign in
-
-
Day 70 of My DSA Journey Problem: Linked List Cycle (LeetCode 141) Today’s problem was all about detecting whether a linked list contains a cycle — a classic and very important concept in data structures. Key Idea: Floyd’s Cycle Detection Algorithm (Tortoise & Hare) Instead of using extra memory, we use two pointers: • Slow pointer → moves 1 step • Fast pointer → moves 2 steps If there’s a cycle, these two pointers will eventually meet. If not, the fast pointer will reach the end (null). Insight: This approach is efficient because it avoids using extra space like a HashSet and still guarantees detection in linear time. Complexity: • Time: O(n) • Space: O(1) What I learned: Sometimes, the smartest solutions don’t require extra space — just a clever observation and pointer manipulation! Consistency > Perfection 💯 On to Day 71 🚀 #DSA #100DaysOfCode #Java #CodingJourney #ProblemSolving #LinkedList
To view or add a comment, sign in
-
-
Today I solved LeetCode 958 – Check Completeness of a Binary Tree. 🧩 Problem Summary: Given the root of a binary tree, determine if it is a complete binary tree. A complete binary tree is defined as: All levels are completely filled except possibly the last level In the last level, nodes are as far left as possible 💡 Key Concepts Used: Binary Trees Breadth First Search (BFS) Queue data structure Tree properties 🧠 Approach: Use BFS (level order traversal) with a queue. Traverse nodes level by level. Once a null node is encountered: All following nodes must also be null. If a non-null node appears after a null, the tree is not complete. Otherwise, the tree satisfies completeness. ⏱ Time Complexity: O(N) — Each node is visited once. 📚 What I Learned: Understanding the properties of a complete binary tree. Using BFS to validate structural constraints. Handling null conditions carefully during traversal. Strengthening queue-based tree problem-solving. Building strong fundamentals in tree structures Consistency is key to mastering DSA #LeetCode #DSA #BinaryTree #CompleteBinaryTree #BFS #Queue #Java #CodingJourney #ProblemSolving #100DaysOfCode #TechGrowth
To view or add a comment, sign in
-
-
Today I solved: Group Anagrams 💡 Key Takeaway: The real trick was not comparing strings directly, but transforming each string into a standard form (sorted or frequency-based) and using it as a key for grouping. 👉 Approaches explored: - Sorting each string and using it as a key - Optimizing further using character frequency (better time complexity) 📊 Complexity: - Sorting approach → O(n * k log k) - Optimized approach → O(n * k) 🔍 What I learned: Many problems become easier when we change how we represent the data instead of solving them directly. Small shift in thinking → big impact in performance 💪 #DSA #LeetCode #Java #CodingJourney #SoftwareEngineering
To view or add a comment, sign in
Explore related topics
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