🚀 Day 33 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Product of Array Except Self Problem Insight: Given an array, return a new array where each element is the product of all other elements except itself, without using division. Approach: • Used prefix (left) product to store multiplication of previous elements • Traversed from right to calculate suffix product • Combined both to get the final answer • Handled cases with zeros without using division Time Complexity: • O(n) Space Complexity: • O(1) (excluding output array) Key Learnings: • Prefix and suffix technique is very useful • Avoiding division helps handle edge cases • Practice improves problem-solving skills Takeaway: Simple patterns like prefix and suffix can solve complex problems easily with practice. #DSA #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving
LeetCode Challenge: Product of Array Except Self Solution
More Relevant Posts
-
🚀 Day 36 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Longest Common Prefix Problem Insight: Find the longest common prefix among an array of strings. If no common prefix exists, return an empty string. Approach: • Assume the first string as the initial prefix • Iterate through the remaining strings • While the current string doesn’t start with the prefix: – Trim the last character of the prefix • Repeat until a common prefix is found or it becomes empty Time Complexity: • O(n × m) — n = number of strings, m = length of prefix Space Complexity: • O(1) — constant extra space Key Learnings: • Reducing the problem step-by-step makes it easier to solve • Shrinking the prefix is often more efficient than building it • Edge case handling (like empty arrays) is crucial Takeaway: Sometimes the best approach isn’t to construct a solution, but to refine it until it fits perfectly. #DSA #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving #Strings
To view or add a comment, sign in
-
-
Solved: Product of Array Except Self 💡 Key Takeaway: Instead of recalculating product for every index, we can use prefix and suffix products to build the result efficiently. 👉 Approach I followed: - First pass → store left (prefix) product - Second pass → multiply with right (suffix) product - No division used 📊 Time Complexity: O(n) 📦 Space Complexity: O(1) 🔍 What made it interesting: Understanding how left and right contributions combine at each index to avoid redundant calculations. Consistency + clarity is slowly building confidence 💪 #DSA #Java #LeetCode #CodingJourney #BackendDeveloper #SoftwareEngineering
To view or add a comment, sign in
-
Solved one of the most interesting problems : Subarray Sum Equals K 💡 Key Takeaway: Instead of checking every subarray, tracking prefix sums helps directly identify valid subarrays in an optimized way. 👉 Key Insight: If (prefixSum - k) has already appeared, it means we found a subarray with sum = k. 📊 Time Complexity: O(n) 📦 Space Complexity: O(n) 🔍 What made it interesting? Understanding how previously seen sums help us avoid rework and directly count valid subarrays. Every day I realize: Consistency and clarity of concepts matter more than just solving problems. 💪 #DSA #Java #LeetCode #CodingJourney #BackendDeveloper #SoftwareEngineering
To view or add a comment, sign in
-
🚀 Day 48 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Sort Array By Parity Problem Insight: Rearrange the array so that all even numbers come before odd numbers. The order of elements doesn’t matter. Approach: • Used the two-pointer technique (partition logic) • Maintained a pointer j to track the position for even numbers • Traversed the array using i • Whenever an even number is found, swapped it with index j and incremented j • This ensures all even elements move to the front in a single pass Time Complexity: O(n) Space Complexity: O(1) (in-place solution) Key Learnings: • Two-pointer technique is very useful for array partitioning problems • Swapping helps avoid extra space usage • This pattern is similar to problems like moving zeros or segregating positives/negatives Takeaway: Simple logic + optimal approach = clean and efficient solution. Consistency is making these patterns easier to recognize! #DSA #Java #LeetCode #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
-
Day 101 - LeetCode Journey Solved LeetCode 856: Score of Parentheses ✅ Looks tricky at first, but turns out to be a neat pattern problem. Instead of using a stack, used depth tracking + bit manipulation to calculate score efficiently. Core idea: Every "()" contributes 2^depth So just track depth and add score at the right moment. Key learnings: • Understanding pattern inside parentheses • Using depth instead of extra space • Bit manipulation for optimization ⚡ • Clean O(n) solution without stack ✅ All test cases passed ⚡ O(n) time | O(1) space Simple logic, powerful result 💡 #LeetCode #DSA #Stack #BitManipulation #Java #CodingJourney #ProblemSolving #InterviewPrep
To view or add a comment, sign in
-
-
#Day357 of #1001DaysOfCode LeetCode Daily Challenge Problem: Decode the Slanted Ciphertext (LeetCode 2075) 💡 Approach: The encoded string represents a matrix filled row-wise. I traversed the matrix diagonally (top-left to bottom-right) by converting 2D indices into a 1D string index. Finally, removed trailing spaces to get the correct decoded message. (*you can use inbuilt .stripTrailing() function as well) ⏱ Time Complexity: O(n) 🧠 Space Complexity: O(n) Staying consistent with daily problem solving 🚀 #DSA #Java #LeetCode #ProblemSolving #Coding
To view or add a comment, sign in
-
-
🚀 Day 570 of #750DaysOfCode 🚀 🔍 Problem Solved: Words Within Two Edits of Dictionary Today’s problem was a nice mix of strings + observation. At first glance, it feels like a transformation problem, but it simplifies beautifully. 💡 Key Insight: We don’t actually need to perform edits. We just need to check how many characters are different between two words. 👉 If the difference (Hamming distance) ≤ 2 → it's valid 🧠 Approach: For each word in queries, compare it with every word in dictionary Count character differences If any comparison has ≤ 2 differences → include the word in result ⚡ Early break helps optimize the solution! 📈 Complexity: Time: O(Q × D × n) Space: O(1) ✨ Takeaway: Not every problem needs simulation — sometimes reducing it to a simple comparison metric (like character differences) makes it much easier. Consistency > Complexity 💪 #LeetCode #DSA #Java #CodingJourney #ProblemSolving #Tech #LearningEveryday #Strings
To view or add a comment, sign in
-
-
🚀 Day 77 — Slow & Fast Pointer (Middle of the Linked List) Another day, another clean application of the slow‑fast pointer pattern — this time without cycle detection, just finding the midpoint efficiently. 📌 Problem Solved: - LeetCode 876 – Middle of the Linked List 🧠 Key Learnings: 1️⃣ The Problem Given the head of a singly linked list, return the middle node. If there are two middle nodes (even length), return the second one. 2️⃣ Why Slow‑Fast Pointer Works Here - `slow` moves 1 step at a time. - `fast` moves 2 steps at a time. - When `fast` reaches the end (or `fast.next == null`), `slow` is exactly at the middle. - For even length, `fast` ends at `null` → `slow` points to the second middle node (perfect for this problem’s requirement). 3️⃣ The Code (Simple & Elegant) while (fast != null && fast.next != null) { slow = slow.next; fast = fast.next.next; } return slow; 4️⃣ Why Not Just Count Then Traverse? - Brute force: count nodes → traverse again → O(n) but two passes. - Slow‑fast pointer achieves the same in one pass with O(1) extra space. 💡 Takeaway: Slow‑fast pointer isn’t only for cycle detection. It’s a versatile tool for: - Finding middle (this problem) - Detecting cycles (LeetCode 141/142) - Finding duplicate numbers (LeetCode 287) - Happy number detection (LeetCode 202) Each problem adds a new dimension to understanding the same pattern. No guilt about past breaks — just showing up, solving, and growing. #DSA #SlowFastPointer #MiddleOfLinkedList #LeetCode #CodingJourney #Revision #Java #ProblemSolving #Consistency #GrowthMindset #TechCommunity #LearningInPublic
To view or add a comment, sign in
-
🚀 Day 66 of #LeetCode Challenge ✅ Problem Solved: Divide a String Into Groups of Size K 💡 What I learned today: • Learned how to break a string into fixed-size groups • Understood how to handle incomplete groups using a fill character • Practiced building strings step-by-step using loops • Improved clarity on index handling and conditions 🧠 Approach: • Traverse the string one character at a time • Build a group until it reaches size k • Store the group and reset • If the last group is smaller, fill remaining positions with the given character 📊 Key Takeaway: Handling edge cases (like incomplete groups) is very important in problem solving 🔥 Consistency is the key — improving step by step every day! #Day66 #LeetCode #CodingJourney #DSA #Java #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 18 of #100DaysOfCode Solved LeetCode 334 – Increasing Triplet Subsequence 📈 Today’s problem was all about optimizing from brute force to a smart greedy approach. Instead of checking all triplets, I tracked the smallest and second smallest values while iterating once through the array. 💡 Key Insight: If we find a number greater than both first and second, an increasing triplet exists! 🔍 What I learned: Greedy approach can reduce time complexity drastically Maintaining two variables is enough to detect a triplet Writing clean and efficient O(n) solutions ⚡ Performance: Runtime: 2 ms (Beats 99.28%) Memory: Solid optimization #DSAwithEdSlash #LeetCode #Java #CodingJourney #ProblemSolving
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