📌 Day 51/100 – Longest Word in Dictionary (LeetCode 720) 🔹 Problem: Given an array of words, find the longest word that can be built one character at a time by other words in the array. If multiple results exist, return the lexicographically smallest one. 🔹 Approach: Built a Trie structure to store all words. Used DFS traversal to explore all valid prefixes (where every prefix forms a valid word). Updated the answer when a longer or lexicographically smaller valid word was found. 🔹 Key Learning: Deepened understanding of Trie traversal with DFS. Practiced combining lexicographical comparison with prefix validation. Reinforced prefix-based word-building logic efficiently. 🔹 Complexity: Time: O(N × L) — N = number of words, L = average word length Space: O(26 × N × L) — for Trie storage #Day51Of100 #LeetCode720 #100DaysOfCode #Java #DSA #Trie #DFS #ProblemSolving #CodingChallenge #Strings #DataStructures #CodingJourney #KeepLearning
Solved LeetCode 720: Longest Word in Dictionary using Trie and DFS
More Relevant Posts
-
🔢 Day 47 of #LeetCode100DaysChallenge Solved LeetCode 79: Word Search — a classic backtracking problem that beautifully blends recursion and grid traversal. 🧩 Problem: Given a 2D grid of characters and a word, determine if the word can be formed using sequentially adjacent cells (up, down, left, right), where each cell can be used only once. 💡 Approach Used — Backtracking (DFS): 1️⃣ Start from each cell that matches the first character. 2️⃣ Explore in all four directions recursively. 3️⃣ Temporarily mark visited cells to avoid reuse. 4️⃣ If the entire word is matched, return true; otherwise, backtrack. ⚙️ Complexity: Time: O(N × 4ᴸ) — where N is the total number of cells, and L is the word length. Space: O(L) — recursion depth. ✨ Key Takeaways: ✅ Strengthened understanding of recursion and backtracking. ✅ Learned to manage visited states effectively in grid problems. ✅ Great exercise in applying DFS to real-world matrix traversal cases. #LeetCode #100DaysOfCode #Java #Backtracking #Recursion #ProblemSolving #DSA #WomenInTech #CodingJourney
To view or add a comment, sign in
-
-
#Day36 Of Problem Solving Successfully solved LeetCode #343 – Integer Break 💡 Achieved an Accepted Solution with 0 ms runtime (beats 100% of Java submissions) 🎯 This problem was a great exercise in mathematical optimization and problem decomposition. The key insight was to maximize the product by breaking the integer into 3’s — leveraging both mathematical reasoning and efficient implementation. 📘 Concepts Used: Mathematical analysis of number partitioning Power function and modular logic Time complexity: O(1) Every solved problem is another step toward mastering algorithmic thinking and optimization ⚡ #LeetCode #Java #Coding #ProblemSolving #Mathematics #DSA #DynamicProgramming #CompetitiveProgramming #LearningJourney #SoftwareEngineering #Consistency #Linkedin #HackerRank
To view or add a comment, sign in
-
-
⚙️ Day 38 of My LeetCode Journey — Problem #2654 “Minimum Number of Operations to Make All Array Elements Equal to 1” (Java Solution) 💡 Today’s challenge beautifully combined number theory with algorithmic optimization. The goal: turn every element in an array into 1 using the minimum operations — and the key insight was rooted in GCD properties. 🔍 My thought process: If any 1s exist → we just need to handle the rest (n - count(1)). Otherwise → find the shortest subarray with GCD = 1, since it’s the only way to generate a 1. The final answer = minimal window length + (n - 1) operations. It’s fascinating how understanding mathematical relationships can drastically simplify code complexity 🔢 Each problem reminds me — elegant logic is what turns code into art 🧠💻 #Day38 #LeetCode #Java #ProblemSolving #NumberTheory #Algorithms #DSA #CodingJourney #100DaysOfCode #CodeEveryday #SoftwareEngineering #LearningInPublic #TechCommunity
To view or add a comment, sign in
-
-
🚀 Day 22 of #GFG160DaysDSAChallenge Today I tackled the H-Index problem (LeetCode 274 / GFG), a classic medium-level problem that tests understanding of arrays, counting, and problem optimization. 💡 Problem Statement: Given an array citations[] representing the number of citations each paper has, compute the H-Index — the maximum h such that the researcher has at least h papers with ≥ h citations. 🔑 My Approach: Brute Force: Check every possible h from 0 → n and count papers with citations ≥ h → O(n²). Better (Sort-based): Sort citations and iterate to find the first index where citations[i] ≥ n - i → O(n log n). Optimal (Counting/Bucket): Create a bucket array to count how many papers have 0…n citations. Iterate from high to low to accumulate papers with ≥ h citations. Return the largest h that satisfies the condition → O(n) ✅ 💡 Key Takeaways: Often, sorting isn’t needed — sometimes just counting frequencies is enough. The problem is a great example of thinking “better → optimal” by exploiting constraints (h ≤ n). Understanding how to aggregate information instead of iterating repeatedly is a big step in DSA. #DSA #100DaysOfCode #GFG160Days #Java #CodingChallenge #LeetCode #ProblemSolving #HIndex
To view or add a comment, sign in
-
-
🌟 Day 44 – LeetCode Practice Problem: Product of Array Except Self (LeetCode #238) 📌 Concept: Given an integer array, create a new array where each element equals the product of all other elements except itself, without using division. 🧠 My Approach: First pass → compute prefix products (multiply everything before current index) Second pass → compute suffix products (multiply everything after current index) Combine both to get the result for each index efficiently No extra multiplication array used — optimized and clean logic ⚡ This avoids division and runs in linear time — exactly what the problem demands ✅ 📈 Result: ✅ Accepted ⚡ Runtime: 2 ms (Beats ~87%) 📦 Memory: Efficient usage 💡 Key Learning: This problem reinforces the power of prefix & suffix computation — a common trick in array manipulation + interview favorite. Great way to improve problem-solving without relying on brute force or division. --- 🚀 Growing stronger every day in DSA! #LeetCode #DSA #Java #ProblemSolving #PrefixSuffix #CodingJourney #ArrayProblems #LearningMindset
To view or add a comment, sign in
-
-
💻 #Day486 (DSA) – LeetCode 3370: Smallest Number With All Set Bits 🔥 🚀 Problem Summary: Given a positive integer n, find the smallest number x ≥ n such that the binary representation of x contains only set bits (1s). 🧩 Examples: Input: n = 5 Output: 7 → Binary: 111 Input: n = 10 Output: 15 → Binary: 1111 Input: n = 3 Output: 3 → Binary: 11 💡 Intuition: To find the smallest number having all bits set, we can compute numbers like: 1 → (1), 3 → (11), 7 → (111), 15 → (1111), 31 → (11111)... and pick the smallest one ≥ n. 🧠 Approach: Keep generating (1 << k) - 1 until the result is ≥ n. That number will be our answer ✅ 🧩 Code (Java): class Solution { public int smallestNumber(int n) { int x = 1; while (x < n) { x = (x << 1) | 1; // shift and set next bit } return x; } } 🕒 Time Complexity: O(log n) 💾 Space Complexity: O(1) ✨ Key Learning: Mastery in bit manipulation 🧠 Smart usage of left shift and bitwise OR Understanding how binary patterns grow 🏷️ Tags: #LeetCode #DSA #BitManipulation #CodingChallenge #ProblemSolving #Java #DeveloperJourney #Algorithms #KeepLearning #CodeEveryday #TechCommunity 💬 Question for you: If you had to generalize this for the next “all-set bit number” above any given n, how would you optimize it? 🤔
To view or add a comment, sign in
-
-
🌳 Day 36/100 ✅ Preorder Traversal of Binary Tree Today I solved the Preorder Traversal problem using recursion. In this traversal method, the order of visiting nodes is simple yet powerful: 👉 Root → Left → Right This problem helped me understand how recursion can naturally handle tree structures by breaking the problem into smaller subproblems. At each recursive call, we visit the root node first, then move to the left subtree, and finally to the right subtree — making the traversal flow smooth and logical. 💡 Key Takeaways: Preorder traversal always starts from the root. Recursion simplifies complex tree navigation into cleaner and readable logic. Visualizing the function call stack helps to truly understand the flow of recursion. Every day, I’m realizing how recursion is not just a coding tool — it’s a way to think step-by-step through structured problems. 🌱 #Day36 #DSA #CodingJourney #BinaryTree #PreorderTraversal #Recursion #ProblemSolving #LearningEveryday #100DaysOfCode #Java
To view or add a comment, sign in
-
-
DSA Practice – Day 52 🚀 Problem: Happy Number (LeetCode 202) 📌 Problem Statement: A number is called happy if repeatedly replacing it with the sum of the squares of its digits eventually leads to 1. Return true if it’s a happy number, otherwise false. 🧩 Brute Force Approach: Keep track of all numbers seen in a set to detect loops. If you reach 1, Happy Number If a number repeats, Not Happy Time Complexity: O(log n) Space Complexity: O(log n) ⚡ Optimal Approach (Floyd’s Cycle Detection): Use two pointers — slow and fast. Move slow by one step and fast by two steps (using sum of squares). If they meet, there’s a cycle (not happy). If you reach 1, it’s a happy number. Time Complexity: O(log n) Space Complexity: O(1) ✨ What I Learned: How to detect cycles in number transformations. Applying Floyd’s cycle detection beyond linked lists. Improved logical problem-solving for number-based questions. #LeetCode #Java #ProblemSolving #DSA #CodingJourney #PlacementPrep
To view or add a comment, sign in
-
-
#Day33 of Problem Solving Successfully solved the “Count Primes” problem 🧮 using the Sieve of Eratosthenes algorithm. ✅ Result: All test cases passed (66/66) ⚡ Runtime: 97 ms — Beats 57.06% of Java submissions 💾 Memory: 49.56 MB This problem deepened my understanding of prime number optimization and time complexity reduction through effective use of boolean arrays and loop boundaries. Every small optimization matters — it’s amazing how algorithmic thinking can turn a simple mathematical problem into a performance challenge. 💡 #LeetCode #Java #Coding #ProblemSolving #SieveOfEratosthenes #Algorithms #DataStructures #CodingJourney #SoftwareEngineering #DSA #LinkedIn #HackerRank
To view or add a comment, sign in
-
-
🌿 Day 74 of #100DaysOfCode 🌿 💡 Problem: Binary Tree Preorder Traversal – LeetCode 🚀 Approach: Used a recursive traversal to explore nodes in the order Root → Left → Right. Preorder traversal is all about visiting the leader first — just like taking the initiative before exploring possibilities! 💫 📊 Complexity Analysis: Time Complexity: O(n)** — every node is visited once Space Complexity: O(n)** — due to recursion stack ✅ Runtime: 0 ms (⚡ Beats 100%) ✅ Memory: 43.06 MB 🔑 Key Insight: Recursion helps untangle even the deepest branches — one root call at a time 🌱 #LeetCode #100DaysOfCode #BinaryTree #Recursion #CodingJourney #DSA #ProblemSolving #Java #Algorithms #ProgrammerLife #WomenInTech #CodeEveryday
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