🌟 Day 76 of #100DaysOfCodingChallenge 📘 Problem: LeetCode 73 – Set Matrix Zeroes Today, I explored an important array manipulation problem — setting entire rows and columns to zero if any element in a 2D matrix is zero. 🧩 Problem Understanding Given an m x n matrix, if any cell has the value 0, we must make its entire row and column 0. For example: Input: [ [1, 2, 3], [4, 0, 6], [7, 8, 9] ] Output: [ [1, 0, 3], [0, 0, 0], [7, 0, 9] ] 💡 My Approach (Brute Force) To handle this, I used two extra arrays — one to track rows and another to track columns that should become zero. 🪄 Steps followed: 1️⃣ Traverse the matrix and store the indices of rows and columns containing 0. 2️⃣ Loop through the matrix again and make the elements 0 wherever their row or column index is marked. This simple approach helps clearly visualize how matrix updates propagate. 🧠 Concept Learned: How to access and manipulate specific rows and columns in a 2D array. The importance of auxiliary data structures (like boolean arrays) in preserving information during traversal. 🕒 Complexity: Time: O(m × n) Space: O(m + n) 🧵 Next Step: I’ll be optimizing this approach to an O(1) space solution using the matrix itself as a marker — a neat trick in in-place algorithms! #100DaysOfCode #Day75 #LeetCode #Java #CodingChallenge #ProblemSolving #ArrayManipulation #DataStructures #WomenInTech
Solved LeetCode 73 – Set Matrix Zeroes with brute force
More Relevant Posts
-
#Day_23 💡 Problem Solved: Intersection of Two Arrays Today’s challenge tested my ability to handle array manipulation and two-pointer logic efficiently. 🧩 Problem Overview: Given two integer arrays, the task is to find their intersection — meaning the common elements between both arrays, including duplicates. For example: nums1 = [4,9,5] and nums2 = [9,4,9,8,4] 👉 Output should be [4,9] (since both 4 and 9 appear in both arrays). ⚙️ My Approach: Sorting both arrays: By sorting nums1 and nums2, I was able to efficiently compare elements in a linear scan. Two-pointer technique: I used two indices i and j, starting from 0 in each array. If both elements matched → it’s part of the intersection. If one was smaller → move that pointer ahead to catch up. Storing results dynamically: Added all matching elements into an ArrayList. Finally converted it into an integer array for the result. This approach ensures O(n log n) time complexity due to sorting, but O(n) in space — a solid balance between clarity and performance. 🧠 Key Takeaways: Sorting simplifies complex comparison problems. The two-pointer pattern is extremely useful for dealing with sorted arrays. Always remember: clean logic > brute force. 🔥 Every new problem brings a fresh perspective on optimizing logic and learning better ways to handle data structures. #Java #CodingChallenge #LeetCode #100DaysOfCode #ProblemSolving #DSA #ProgrammingJourney #TechWithMudassir
To view or add a comment, sign in
-
-
#Day_24 💡 Problem Solved: Intersection of Two Arrays II Today’s challenge tested my ability to handle array manipulation and two-pointer logic efficiently. 🧩 Problem Overview: Given two integer arrays, the task is to find their intersection — meaning the common elements between both arrays, including duplicates. For example: nums1 = [4,9,5] and nums2 = [9,4,9,8,4] 👉 Output should be [4,9] (since both 4 and 9 appear in both arrays). ⚙️ My Approach: Sorting both arrays: By sorting nums1 and nums2, I was able to efficiently compare elements in a linear scan. Two-pointer technique: I used two indices i and j, starting from 0 in each array. If both elements matched → it’s part of the intersection. If one was smaller → move that pointer ahead to catch up. Storing results dynamically: Added all matching elements into an ArrayList. Finally converted it into an integer array for the result. This approach ensures O(n log n) time complexity due to sorting, but O(n) in space — a solid balance between clarity and performance. 🧠 Key Takeaways: Sorting simplifies complex comparison problems. The two-pointer pattern is extremely useful for dealing with sorted arrays. Always remember: clean logic > brute force. 🔥 Every new problem brings a fresh perspective on optimizing logic and learning better ways to handle data structures. #Java #CodingChallenge #LeetCode #100DaysOfCode #ProblemSolving #DSA #ProgrammingJourney #TechWithMudassir
To view or add a comment, sign in
-
-
💻 Day 63 of #LeetCode100DaysChallenge Solved LeetCode 290: Word Pattern — a great problem for strengthening hash mapping and bijection logic between characters and words. 🧩 Problem: Given a pattern and a string s, determine if s follows the same pattern. Each letter in the pattern maps to exactly one unique word in s, and each unique word in s maps to exactly one letter in the pattern. No two letters map to the same word, and no two words map to the same letter. 💡 Approach — HashMap + Set: 1️⃣ Split s into words. If pattern length ≠ word count, return false. 2️⃣ Use two data structures: A HashMap<Character, String> to map pattern → word. A HashSet<String> to track if a word is already mapped. 3️⃣ Iterate through both: If the character was seen before, check if it maps to the same word. If it’s new, ensure the word isn’t already mapped to another letter. 4️⃣ Return true if all pairs match consistently. ⚙️ Complexity: Time: O(N) — one pass through all words. Space: O(N) — for the map and set. ✨ Key Takeaways: ✅ Strengthened understanding of bijections and hash-based pattern matching. ✅ Improved clarity on how to manage two-way mapping between characters and strings. ✅ Practiced clean iteration and map validation logic — crucial for real-world parsing and pattern-matching problems. #LeetCode #100DaysOfCode #Java #HashMap #PatternMatching #DSA #ProblemSolving #WomenInTech #CodingChallenge
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 66 String Manipulation & Primitive Decomposition 🧩 Task: Given a valid parentheses string, decompose it into its primitive components and then remove the outermost parentheses from each component. Example: Input: s = "(()())(())" Primitive Decomposition: "(()())" + "(())" After removing outermost parentheses: "()()" + "()" Output: "()()()" My Approach: I iterated through the string while keeping a counter to track the balance of open parentheses. When an opening parenthesis ( was found, I incremented the counter. If the count was greater than 1, it meant this parenthesis was not an outermost one, so I appended it to the result. When a closing parenthesis ) was found, I only appended it if the counter was greater than 1 before decrementing. This ensures the final closing parenthesis of a primitive part is excluded. This simple counter-based approach effectively identifies and removes the correct parentheses without needing a more complex data structure like a stack. Time Complexity: O(N) Space Complexity: O(N) Sometimes, a simple counter is all you need to elegantly handle nested structures. It can be a clean and efficient alternative to more complex data structures for certain problems. #takeUforward #100DaysOfCode #Java #ProblemSolving #LeetCode #DataStructures #Algorithms #StringManipulation #CodeNewbie
To view or add a comment, sign in
-
-
🔥 Day 35/100 of #100DaysOfCode - Finding Longest Sequence! Today's Problem: Longest Consecutive Sequence Task: Find the length of the longest consecutive elements sequence in an unsorted array. Solution: Used a HashSet for O(1) lookups! First added all elements to the set, then for each number, checked if it's the start of a sequence (no num-1 in set). If yes, counted consecutive numbers ahead. Key Insights: O(n) time complexity by only checking sequence starters HashSet eliminates duplicates and provides fast lookups Avoids O(n log n) sorting approach Smart Optimization: Only begins counting from sequence starting points Each number is processed at most twice (visited in set iteration + sequence counting) Handles duplicates and empty arrays gracefully Elegant solution that transforms an O(n²) brute force into O(n) using smart data structure choice! 💡 #100DaysOfCode #LeetCode #Java #Algorithms #HashSet #Arrays #CodingInterview
To view or add a comment, sign in
-
-
🚀 Just solved LeetCode #105 – Construct Binary Tree from Preorder and Inorder Traversal 🌳✅ 🧩 Problem: Given two integer arrays, preorder and inorder, where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the same tree, the goal is to construct and return the binary tree. 💡 My Approach: I used recursion to rebuild the tree based on the properties of preorder and inorder traversals. 1️⃣ The first element of the preorder array is always the root of the tree. 2️⃣ Find that root in the inorder array — elements to the left form the left subtree, and elements to the right form the right subtree. 3️⃣ Recursively build the left and right subtrees using the corresponding segments of preorder and inorder arrays. 4️⃣ Return the constructed root node once the recursion completes. This approach efficiently utilizes the traversal properties to reconstruct the binary tree from scratch. 🌲 📘 What I Learned: 🌱 Strengthened my understanding of how preorder and inorder traversals relate to each other. 🧠 Gained deeper insight into recursive problem-solving and subarray management. 🔁 Improved my ability to think recursively and break down problems into smaller components. 💻 Appreciated how recursion beautifully models hierarchical data structures like trees. #LeetCode #Java #ProblemSolving #CodingJourney #DataStructures #BinaryTree
To view or add a comment, sign in
-
-
🚀 Today’s DSA Challenge: Vertical Order Traversal of a Binary Tree (LeetCode 987) This problem was quite interesting and taught me how powerful combinations of data structures can be when used smartly. The goal: Given a binary tree, we need to return its vertical order traversal — where nodes are grouped by their column index (left to right), and for each column, nodes are sorted first by row, then by their value. Here’s how I approached it 👇 🔹 I used a TreeMap<Integer, TreeMap<Integer, PriorityQueue<Integer>>> to store nodes in this structure: column -> row -> minHeap of node values This ensures everything stays sorted automatically (both columns and rows). 🔹 I performed a BFS traversal using a Queue<Tuple> where each Tuple stores (node, row, col) coordinates. Whenever I go left, column decreases by 1; when I go right, it increases by 1. 🔹 After traversing the entire tree, I built the final list column by column, row by row. This problem really strengthened my understanding of: ✅ BFS traversal on trees ✅ Nested TreeMaps for maintaining sorted ordering ✅ PriorityQueue usage to resolve same-row value ordering ➡️ Time & Space Complexity Analysis Time Complexity: O(N log N) 👉 Each node is visited once during BFS (O(N)), and every insertion and retrieval in the nested TreeMap + PriorityQueue takes O(log N) time. Space Complexity: O(N) 👉 Because we store all nodes in the map, queue, and result list during traversal. #Java #DSA #LeetCode #BinaryTree #LearningJourney #Coding #Software Engineer #InterviewPreparation #Problem Solving
To view or add a comment, sign in
-
-
💻 Day 60 of #LeetCode100DaysChallenge Solved LeetCode 208: Implement Trie (Prefix Tree) — a problem that strengthens understanding of data structures, string manipulation, and efficient prefix-based searching. 🧩 Problem: Design and implement a Trie (Prefix Tree), a data structure used to efficiently store and retrieve strings. Tries are widely used in autocomplete systems, spell checkers, and prefix-based search algorithms. The Trie class should support the following operations: insert(String word) → Inserts a word into the trie. search(String word) → Returns true if the word exists in the trie. startsWith(String prefix) → Returns true if there’s any word starting with the given prefix. 💡 Approach — Trie Node Structure: 1️⃣ Each Trie node contains: An array or map to store children nodes (typically of size 26 for lowercase letters). A boolean flag isEnd to mark the end of a word. 2️⃣ For insert: Traverse the Trie, creating nodes as needed for each character. Mark the last node as the end of the word. 3️⃣ For search: Traverse nodes following each character; if missing, return false. At the end, return true only if isEnd is marked. 4️⃣ For startsWith: Traverse nodes for each character of prefix; if all exist, return true. ⚙️ Complexity: Time: O(N) per operation, where N = length of the word/prefix. Space: O(N × AlphabetSize) — for all inserted words. ✨ Key Takeaways: ✅ Mastered Trie data structure fundamentals. ✅ Strengthened understanding of prefix-based storage and lookup. ✅ Gained insight into applications like autocomplete and word suggestion systems. #LeetCode #100DaysOfCode #Java #Trie #PrefixTree #DataStructures #DSA #CodingJourney #WomenInTech #Autocomplete #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 28 of #100DaysOfCode Today’s challenge was all about understanding frequency patterns in arrays — a simple yet powerful concept in hashing 🔍 LeetCode 1207 – Unique Number of Occurrences 🔢 📌 Problem Summary: Given an integer array, determine whether each value appears a unique number of times. In other words, 👉 No two numbers should share the same frequency. 💡 Example: Input: [1,2,2,1,1,3] Output: true Because frequencies are: 1 → 3 times 2 → 2 times 3 → 1 time All unique ✔️ 🧠 My Approach: I solved it using a combination of HashMap + HashSet: 1️⃣ Count the occurrences of each number using a HashMap. 2️⃣ Insert all frequency values into a HashSet. 3️⃣ If the size of the HashSet equals the size of the map → all frequencies are unique ✔️ 4️⃣ Otherwise → duplicates exist ❌ A clean and efficient hashing technique. ⚙️ Complexity: Time: O(n) ⏱️ Space: O(n) 💾 (storing frequencies) 💡 Key Learning: HashMaps aren’t just for storing counts—they can reveal patterns, validations, and uniqueness constraints when combined with sets. This problem reinforced how frequency-based logic solves many real-world scenarios like: ✔ Detecting duplicates ✔ Comparing patterns ✔ Character/string analysis ✔ Data validation 🔥 Result: Code ran successfully with 0 ms Runtime, accepted on the first attempt! Small challenge, clean logic, satisfying finish 💪 On to the next one! 🚀 #100DaysOfCode #LeetCode #HashTable #Java #ProblemSolving #DSA #CodingJourney
To view or add a comment, sign in
-
-
Day 3 — Median of Two Sorted Arrays Today’s focus was on one of the most popular LeetCode problems : "Median of Two Sorted Arrays.” The goal: merge two sorted arrays and find their median. At first glance, it feels simple — but getting it right with edge cases is where the logic truly kicks in. Used a two-pointer merge approach — merging elements in order until both arrays are traversed. Once the merged array is ready, finding the median becomes straightforward. It’s one of those problems that looks basic but builds a strong foundation for array manipulation and binary search-based optimizations later on. Slow progress, steady learning.. Similar problems: 🔹 Merge Sorted Array — LeetCode #88 🔹 Kth Element of Two Sorted Arrays (variation of this problem, often asked in interviews) 🔹 Find the Median from Data Stream — LeetCode #295 #100DaysOfDSA #LeetCode #Java #Arrays #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