💪 Day 8 of 100 Days of LeetCode 📘 Problem: #238. Product of Array Except Self 💻 Difficulty: Medium 🔍 Concept: Given an array nums, return an array where each element is the product of all numbers except itself — without using division and in O(n) time. ⚙️ Approach Used: Computed prefix (left) and suffix (right) products. Combined them to get the final result for each index. Optimized without using extra space for readability in future iterations. 🧠 Key Learnings: Strengthened understanding of prefix-suffix product pattern. Practiced space optimization strategies and handling edge cases like zeros. 💻 Code (Java): class Solution { public int[] productExceptSelf(int[] nums) { int n = nums.length; int[] ans = new int[n]; int left = 1, right = 1; for (int i = 0; i < n; i++) { ans[i] = left; left *= nums[i]; } for (int i = n - 1; i >= 0; i--) { ans[i] *= right; right *= nums[i]; } return ans; } } 🔥 Reflection: This problem was a great reminder that division isn’t always the solution — sometimes, breaking a problem into smaller cumulative parts gives a cleaner and more efficient result. #100DaysOfLeetCode #Day8 #CodingChallenge #Java #LeetCode #DSA #ProblemSolving #LearningJourney
"Day 8 of 100 Days of LeetCode: Product of Array Except Self"
More Relevant Posts
-
🚀 Day 59 of #100DaysOfCode 🚀 🔹 Problem: Check if Digits Are Equal in String After Operations I – LeetCode ✨ Approach: Used an iterative reduction strategy 🔁 — repeatedly combined adjacent digits (mod 10) until only two numbers remained. Finally checked if both digits are equal! Simple yet logical 🧠 ⚡ Complexity Analysis: Time Complexity: O(n²) – iterative pairwise reduction until only two digits remain Space Complexity: O(n) – storing intermediate list of digits 📊 Performance: ✅ Runtime: 10 ms (Beats 35.69%) ✅ Memory: 45.51 MB (Beats 12.86%) 🔑 Key Insight: Sometimes, brute-force reduction problems aren’t about optimization — they’re about translating logic into clean code that mirrors the operation flow perfectly. ✨ #LeetCode #100DaysOfCode #Java #DSA #ProblemSolving #CodingChallenge #LogicBuilding #ProgrammingJourney #DailyCoding
To view or add a comment, sign in
-
-
🚀 Day 11 of 100 Days of LeetCode! 💻 Today’s problem: Implement strStr() 🔍 🧩 Problem #28: Find the Index of the First Occurrence in a String This problem is a classic example of string pattern matching, where we need to find the starting index of a substring (needle) in a given string (haystack). ✨ My Approach: Used a simple sliding window technique to check each substring of haystack with length equal to needle. Compared it directly using equals() to find a match. Time complexity: O((n - m + 1) * m), which is acceptable for moderate input sizes. ✅ Result: All test cases passed successfully — and achieved 100% runtime efficiency ⚡ Each day I’m learning to think more efficiently and write cleaner, more optimized code. Consistency really is the key 🔑 #Day11 #100DaysOfCode #LeetCode #Java #ProblemSolving #CodingJourney #SoftwareDevelopment #DSA
To view or add a comment, sign in
-
-
💡 Day 10 of 100 Days of LeetCode 📘 Problem: #26. Remove Duplicates from Sorted Array 💻 Difficulty: Easy 🔍 Concept: The task is to remove duplicates in-place from a sorted array so that each unique element appears only once. The function should return the count of unique elements k. ⚙️ Approach Used: Used two-pointer technique — one pointer (k) tracks the position of the last unique element, and the other (i) scans the array. Whenever a new unique element is found, it’s moved to the next position in the array. 🧠 Key Learnings: Mastered the in-place modification concept in arrays. Learned how to use two-pointer pattern for linear-time solutions. Refined logic building with minimal extra space usage (O(1) space). 💻 Code (Java): class Solution { public int removeDuplicates(int[] nums) { int k = 0; for (int i = 1; i < nums.length; i++) { if (nums[i] != nums[k]) { k++; nums[k] = nums[i]; } } return k + 1; } } 💬 Reflection: A simple-looking problem — but it’s one that trains you to think in space-efficient ways. Sometimes, mastering basics is what builds strong problem-solving intuition! #100DaysOfLeetCode #Day10 #DSA #Java #ProblemSolving #CodingChallenge #LeetCode #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 6 of Improving Problem-Solving Today, I solved LeetCode 27: Remove Element, which at first looked like an easy problem but required careful thinking to arrive at an optimal in-place solution. 🧩 Problem Statement: Given an array nums and a value val, remove all occurrences of val in-place and return the number of elements not equal to val. ⚙️ Approach Used: Two Pointers Technique To solve this efficiently, I applied the two-pointer approach, which helps modify arrays in place without extra space. 🔹 Logic Explained: Use two pointers, i and j. j scans each element, while i tracks the position where the next valid (non-val) element should go. If nums[j] != val, assign nums[i] = nums[j] and increment both i and j. This way, all valid elements are shifted to the front, and duplicates or unwanted values are removed efficiently. 💡 This problem helped me strengthen my understanding of in-place algorithms and how two-pointer logic can simplify seemingly tricky problems. Each day, I’m realizing that solving problems isn’t just about getting the right answer — it’s about improving clarity, logic, and consistency. #Day6 #ProblemSolving #DSA #TwoPointers #LeetCode #Java #CodingJourney
To view or add a comment, sign in
-
-
🚀Day 5️⃣9️⃣of #100DaysOfCode Solved LeetCode 3354 – Make Array Elements Equal to Zero 🧮 ⚡ Runtime: 1 ms (Beats 83.13%) 📊 Memory: 42.10 MB (Beats 69.28%) 🔍 Concept: This problem revolves around array traversal, directional logic, and state transitions. You start from an index where the element is 0 and move left or right while updating values and reversing direction — until all elements reach zero. 🧩 Approach Summary: Identify the initial index containing 0. Traverse left and right, updating values and counting valid selections. Keep it simple, linear, and effective. Some problems test patience as much as skill — but every solved logic strengthens the problem-solving mindset. #LeetCode #Java #ProblemSolving #100DaysOfCode #CodingJourney #SoftwareEngineer #Developer #AlgorithmDesign #Consistency #LearningEveryday
To view or add a comment, sign in
-
-
✨ Day 57 of 100: Rotate List ✨ Today’s challenge was LeetCode 61 – Rotate List 🔄 Problem: Given the head of a linked list, rotate the list to the right by k places. Example: Input: head = [1,2,3,4,5], k = 2 Output: [4,5,1,2,3] Key Idea: To rotate the list: 1️⃣ Find the length of the linked list. 2️⃣ Connect the tail to the head to make it circular. 3️⃣ Calculate the new head position as length - (k % length) steps from the start. 4️⃣ Break the circle at the right point to get the rotated list. 💡 Key Takeaways: Strengthened understanding of linked list traversal and manipulation. Learned to handle edge cases like k larger than the list length efficiently using modulo. Practiced converting a circular list back into a normal one at the right node. 💬 Every day of this challenge reinforces how small logical tweaks — like using % to handle rotations — can make code elegant and efficient. #100DaysOfCode #LeetCode #Java #LinkedList #CodingChallenge #DSA #ProblemSolving #WomenWhoCode
To view or add a comment, sign in
-
-
🌟 Day 84 of My #100DaysOfCode Challenge 🧩 Problem: LeetCode 108 – Convert Sorted Array to Binary Search Tree 💭 Understanding the Problem Given a sorted array, we need to convert it into a height-balanced Binary Search Tree (BST) — meaning the difference in height between the left and right subtrees of every node should not exceed one. 📘 Example: Input: nums = [-10, -3, 0, 5, 9] Output: [0, -3, 9, -10, null, 5] The middle element (0) becomes the root, left half forms the left subtree, and the right half forms the right subtree. 🧠 Key Idea Pick the middle element as the root for balance. Recursively repeat the same for left and right halves. This approach ensures that the BST remains balanced. ⚙️ Complexity Analysis Time Complexity: O(n) — each element is processed once. Space Complexity: O(log n) — recursion stack in a balanced tree. ✨ Takeaway This problem beautifully combines recursion and binary tree logic, showcasing how dividing the array strategically helps maintain balance in a BST. 💬 "Balanced structures are key to efficiency — both in code and in life!" 😄 #Day84 #LeetCode #Java #DSA #BinaryTree #CodingChallenge #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 20 of #Blind75 Challenge 🎯 Problem: Merge Two Sorted Lists 🧩 Platform: LeetCode (#21) 💡 Category: Linked List 🧠 Problem Statement Given the heads of two sorted linked lists, merge them into a single sorted linked list and return its head. Example: Input: List1 = 1 → 2 → 4 List2 = 1 → 3 → 4 Output: 1 → 1 → 2 → 3 → 4 → 4 💡 Intuition This problem is all about two-pointer merging, similar to how you merge arrays in merge sort. We use a dummy node to simplify pointer handling. Then, at each step: Compare list1.val and list2.val Attach the smaller one to the merged list Move that list’s pointer forward Finally, append the remaining nodes. ⚙️ Complexity ⏱ Time: O(m + n) 💾 Space: O(1) ✨ Key Takeaway A clean example of how a dummy node simplifies linked list merging. This logic forms the foundation for many advanced problems like “Merge K Sorted Lists” and “Sort Linked List.” ✅ Day 20 of #Blind75 completed! Next up → Linked List Cycle Detection 🔁 📚 Full solutions available at my LeetCode profile: 👉 https://lnkd.in/gGEwKNFV #Blind75 #LeetCode #Java #LinkedList #DSA #CodingChallenge #ProblemSolving #CareerGrowth #100DaysOfCode #TechJourney
To view or add a comment, sign in
-
-
Today’s problem: Merge Two Sorted Lists 🔗 Problem: Given two sorted linked lists, merge them into one sorted list and return it. Example: Input: list1 = [1,2,4], list2 = [1,3,4] Output: [1,1,2,3,4,4] Approach I used: ✅ Create a dummy node to simplify pointer operations. ✅ Use a pointer (tail) to build the merged list by comparing the heads of both lists. ✅ Append the smaller node each time and move forward. ✅ When one list ends, attach the remaining nodes of the other. A clean iterative solution that keeps the space usage minimal (O(1) extra space). ⚡
To view or add a comment, sign in
-
-
✨ Day 54 of 100: Reverse Nodes in k-Group ✨ Today’s challenge was LeetCode 25 – Reverse Nodes in k-Group 🔁 🧩 Problem: Given a linked list, reverse the nodes of the list k at a time and return its modified list. If the number of nodes is not a multiple of k, the remaining nodes should remain as-is. 💡 Key Takeaways: 🔹 Strengthened understanding of linked list manipulation and pointer handling. 🔹 Practiced breaking the list into segments of size k and reversing each group independently. 🔹 Learned how to manage head and tail connections between reversed and remaining parts. 🔹 Reinforced problem-solving using dummy nodes to simplify list operations. 🧠 Approach: 1️⃣ Count the total nodes to know how many full groups of k exist. 2️⃣ For each group, reverse k nodes iteratively. 3️⃣ Connect the reversed group to the next segment. 🧭 Insight: This problem beautifully illustrates how iteration with precise pointer movement can replace recursion while still achieving elegant reversals in linked lists. #100DaysOfCode #Day53 #LeetCode #Java #LinkedList #CodingJourney #DSA #ProblemSolving
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