🚀 [Day 11/30] Coding Challenge #30DaysOfCode 💡 Problem: Set Matrix Zeroes Today’s challenge tested my ability to balance time and space complexity efficiently — the task was to modify a matrix such that if any element is 0, its entire row and column should be set to zero. I explored multiple approaches before reaching an optimal one 👇 1️⃣ Brute Force Approach: I iterated through the entire matrix, and whenever I found a 0, I used a helper function to mark all elements in its row and column as -1. After completing this marking process, I did another pass to convert all -1 values to 0. ✅ Simple logic, but inefficient due to multiple passes and extra checks. 2️⃣ Using Extra Arrays: Next, I maintained two separate arrays — one for rows and one for columns — to keep track of which rows and columns should become zero. This improved clarity and avoided redundant marking. 🧠 Time Complexity: O(m × n) | Space Complexity: O(m + n) 3️⃣ Optimized In-Place Solution: Finally, I optimized further by using the first row and first column of the matrix itself as markers — eliminating the need for extra space. This reduced the space complexity to O(1) while maintaining O(m × n) time complexity. ✨ It was fascinating to see how a small shift in perspective (reusing the same matrix for storage) made the solution much more elegant and efficient. 🔍 Key Takeaways: Always aim to optimize space without compromising clarity. Sometimes, the best memory to use is the one already in use! 😄 Breaking a problem into stages (brute force → optimized) builds strong problem-solving intuition. eager for next day challenge with Educative. #Day11 #CodingChallenge #Educative #DSA #ProblemSolving #JavaScript #LearningJourney #KeepCoding #Matrix #Optimization #CleanCode
"Optimizing Matrix Zeroes with JavaScript"
More Relevant Posts
-
🚀 [Day 16/30] Coding Challenge Journey with @Educative.io 💻 💡 Problem: Find Longest Self-Contained Substring Today’s challenge was a unique string problem — finding a substring whose characters appear only inside that substring and nowhere else in the entire string. The tricky part? The substring also cannot be the entire string itself. This wasn't a typical sliding window or two-pointer problem, so I had to rethink the approach. My thought process went like this: 1️⃣ Track global character boundaries I first stored the first and last occurrence of every character in the string. This gave me complete information about where each character “lives” inside the string. 2️⃣ Expand substrings smartly Starting from each possible beginning character, I gradually expanded the substring and checked: Do all characters in this substring stay within these boundaries? Is the substring self-contained (i.e., no character appears outside)? 3️⃣ Verify valid windows A substring becomes valid only when: It fully covers all characters within its start–end boundary It is not equal to the full string Every time this condition was satisfied, I tracked its length. This required careful boundary management — but once the logic clicked, the entire substring validation became systematic and efficient ✨ 🔍 Key Learnings: String problems often get easier when you precompute first/last occurrences. Not all problems fit sliding windows — sometimes, boundary-based expansion is the cleaner approach. A substring’s “independence” can be reasoned about using global character positions. ✨ Small win — breaking this problem down into character intervals turned a confusing condition into a clean, workable solution! #30DaysOfCode #Day16 #CodingChallenge #Educative #DSA #JavaScript #StringAlgorithms #ProblemSolving #LearningJourney #KeepCoding
To view or add a comment, sign in
-
Day 31 of #100DaysOfCode – Building Logic with Conditions and Loops in JavaScript Today’s session focused on strengthening core programming logic using conditional statements and loops. Key Learnings: Understood how if, else if, and else conditions control program flow. Explored looping structures to execute repetitive tasks efficiently. Learned how combining these concepts helps in building real-world logic and problem-solving patterns. Takeaway: Mastering loops and conditions is the foundation for writing efficient, dynamic, and logical code in JavaScript. Grateful to Harsh Vandana Sharma from Sheryians Coding School and Sheryians Coding School Community for guiding us through today’s session with clear explanations and practical logic-building examples. #100DaysOfCode #JavaScript #WebDevelopment #CodingJourney #Frontend #ProgrammingLogic
To view or add a comment, sign in
-
-
🚀 Day 4 | 30-Day Coding Challenge – Educative.io Today’s problem: Find the single non-duplicate element in a sorted array. At first, I explored the simple O(n) approaches — 🔹 Using a Set to track duplicates (O(n) time + O(n) space) 🔹 Summing unique vs. total values and finding the difference (O(n) time) 🔹 Linear scan comparing curr and next (O(n) time, O(1) space) All worked… but the goal was O(log n) time and O(1) space. Then it clicked 💡 — since the array is sorted, every pair of equal numbers appears side-by-side. Before the unique element, pairs start at even indices; after it, they start at odd indices. Using this pattern with binary search, I halved the search space each step: if nums[mid] == nums[mid+1] → move right else move left. Every challenge so far is sharpening how I reason about patterns and constraints rather than just syntax. #Day4 #30DaysOfCode #Educative #JavaScript #BinarySearch #ProblemSolving #DSA #LearningInPublic
To view or add a comment, sign in
-
#Day47 of Sheryians Coding School 🚀 1️⃣Self Study: Events & Event Handling (Part 2) Explored advanced event behavior and control in JavaScript. preventDefault() - Stops default browser actions. Example: Preventing page reload on form submit. Event Delegation: Instead of adding event listeners to multiple child elements, attach one listener to the parent and detect which child triggered it. Efficient for dynamic elements. Event Bubbling: Event travels from child → parent. Happens by default. Event Capturing: Event travels from parent → child first. Enabled by passing true as the third parameter in addEventListener. Learned that every event has two phases in its lifecycle: Capturing Phase Bubbling Phase Understanding these phases helped clarify how event flow actually works inside the browser. 2️⃣Self Task: Continued on previous webpage Updated the Event Collection Webpage with: preventDefault implementation Event bubbling examples Event capturing demos Event delegation interactive section Experimentation helped solidify the concepts better. This marks the completion of the webpage module Source: https://lnkd.in/dHJprsvy Live: https://lnkd.in/dVCQtpcx 3️⃣Live Class: Practiced logic-building JS questions. Focused on breaking problems into smaller steps and reasoning clearly. ✨ Key Highlights: Gained deeper clarity on how events flow in the DOM. Learned to write more efficient JS using event delegation. Completed a hands-on project consolidating part 1 + part 2 of events. Improved debugging skills by observing behavior in dev tools. #update #progress #coding #journey #frontend #development #javascript #DOM #manipulation #improving
To view or add a comment, sign in
-
Day 34 | Cohort 2.0 Journey🔁✨ Today’s session was all about controlling the flow of logic in JavaScript by Harsh Vandana Sharma from Sheryians Coding School learning how decisions and repetitions are handled inside programs. 🧠 Key Concepts Covered: 🔹 if, else if, and else : Basic conditional branching 🔹 Truthy & Falsy Values : Understanding values like 0, "", undefined, NaN, null, and even document.all 🔹 Ternary Operator : Shorter way to write conditions 🔹 Switch Case : Cleaner multi-condition handling 🔹 Loops : Starting with for loop to repeat actions efficiently These are the real backbone of logic writing, helping us make our code smart, dynamic, and interactive ⚡ #Day34 #JavaScript #Conditionals #Loops #FrontendDeveloper #Cohort2 #LearningJourney #SheryiansCodingSchool
To view or add a comment, sign in
-
🚀 Day 57 of My LeetCode Journey 🚀 🔹 Today I solved Longest Common Prefix. Key Idea: To find the longest common prefix in a list of strings, we assume the first string as the prefix and gradually shrink it while checking with every other string. The moment a string doesn't start with the prefix, we trim the prefix until it matches — or becomes empty. 💡 What I learned: String operations like startsWith() can simplify logic. Sometimes, a simple greedy shrinking approach performs better than overthinking the solution. Clean code > complex code. 🧠 Takeaway: Break the problem into smaller checks. Don’t force complexity when simplicity solves it efficiently. Here’s the mindset: ➡️ Small progress every day still counts as progress. ➡️ Consistency beats intensity. #100DaysOfCode #leetcode #codingjourney #java #programming #learning
To view or add a comment, sign in
-
-
🚀 [Day 12/30] Coding Challenge Journey with @Educative.io 💻 💡 Problem: Count Subarrays With Fixed Bounds Today’s challenge really tested my understanding of subarray patterns and sliding window logic. The task was to count all subarrays where the minimum and maximum values are exactly equal to given bounds — minK and maxK. At first, my approach was brute force — I generated all possible subarrays, calculated the min and max for each, and increased the count if they matched. It worked, but with a painful O(n² + n) time complexity 😅 Then came the optimization breakthrough 💡 — I introduced three variables: badIndex → to mark positions where elements go out of range minIndex and maxIndex → to store the latest positions of valid min and max For each element, if it stayed within bounds, I could efficiently calculate how many valid subarrays ended at that index by using: count += Math.max(0, Math.min(minIndex, maxIndex) - badIndex) This reduced the complexity to O(n) and turned an expensive brute force into a clean, efficient linear pass ⚡ 🔍 Key Learnings: Identifying invalid states early (like badIndex) saves massive computation. Most subarray problems can be optimized using index tracking instead of recalculating repeatedly. Optimization isn’t about writing less code — it’s about thinking one step deeper 🧠 ✨ Small win — seeing how a few well-chosen variables can simplify a seemingly complex logic! #30DaysOfCode #Day12 #CodingChallenge #DSA #Educative #ProblemSolving #JavaScript #SlidingWindow #Optimization #KeepCoding #LearningJourney #Subarrays
To view or add a comment, sign in
-
🚀 [Day 15/30] Coding Challenge Journey with @Educative.io 💻 💡 Problem: Similar String Groups Today’s problem was all about identifying relationships between strings and grouping them based on their “similarity.” Two strings are considered similar if they differ in exactly two character positions — meaning you can swap those characters to transform one into the other. My intuition started with this core idea: 👉 If two strings differ by exactly two positions, they belong to the same group. To solve this, I approached the problem like a graph traversal challenge: 1️⃣ Consider each string as a node in a graph. 2️⃣ Create an edge between two nodes if the strings differ by exactly two characters. 3️⃣ Use DFS to explore all connected strings that form a similarity group. 4️⃣ Maintain a visited array to ensure each string is processed once. So for each unvisited string, I triggered a DFS call. That DFS marked all strings connected to it (all strings that were similar by 2-character difference). This naturally formed groups of similar strings — each connected component counted as one group. This problem beautifully reinforced how string similarity + graph connectivity can come together to form a clean and efficient solution 🧠✨ 🔍 Key Learnings: Many string problems hide an underlying graph structure — discovering it is half the solution. DFS is extremely powerful for grouping, clustering, and connectivity problems. A simple rule (differ by 2 characters) can create surprisingly complex group relationships. ✨ Small win — once I mapped the problem to graph traversal instead of brute-force comparisons, everything became much more intuitive! #30DaysOfCode #Day15 #CodingChallenge #Educative #DSA #GraphTheory #DFS #JavaScript #ProblemSolving #StringAlgorithms #LearningJourney #KeepCoding
To view or add a comment, sign in
-
🚀 [Day 13/30] Coding Challenge Journey with @Educative.io 💻 💡 Problem: Course Schedule Today’s challenge was all about dependency management — figuring out whether it’s possible to finish all courses given their prerequisites. Essentially, it’s a graph problem disguised as a real-world scheduling issue 🎓 At first, my intuition was to use DFS (Depth First Search) to detect cycles — because if there’s a cycle, you can’t complete all courses. But as I explored further, I realized there’s a more intuitive approach: Topological Sorting using BFS (Kahn’s Algorithm). Here’s how I approached it step by step: 1️⃣ Built a graph representation from the prerequisites list. 2️⃣ Calculated the in-degree (number of incoming edges) for each course. 3️⃣ Used a queue to process all nodes (courses) with zero in-degree — meaning no dependencies. 4️⃣ Repeatedly removed nodes from the queue, reducing the in-degree of dependent nodes. 5️⃣ If all nodes were processed successfully, it meant the course order was possible ✅ This method helped identify cycles efficiently and made the logic easy to reason about — truly a satisfying example of graph traversal in action 🧠 🔍 Key Learnings: Many real-world problems (like task scheduling or project dependencies) can be modeled as graphs. Topological Sort is a must-know technique for problems involving order and precedence. Sometimes, the cleanest logic comes from thinking in terms of relationships, not just data. ✨ Small win — once I saw the connection between course dependencies and graph theory, the problem instantly clicked! #30DaysOfCode #Day13 #CodingChallenge #Educative #DSA #JavaScript #GraphAlgorithms #TopologicalSort #ProblemSolving #LearningJourney #KeepCoding #ProgrammersLife
To view or add a comment, sign in
-
Leetcode problem solving day 85 today i solved problem number 34. Find First and Last Position of Element in Sorted Array link to problem - https://lnkd.in/gdNJs872 below is my approch used function findBound which takes three arguments: array, the target to search for, and a boolean value isFirst which indicates if we are trying to find the first or the last occurrence of target. used 2 variables to keep track of subarray that we are scanning begin and end. begin is set to 0 and end is set to the last index of the array. iterated until begin is greater than to end. at each step calculated middle element mid = (begin + end) / 2. used value of the middle element to decide which half of the array we need to search. nums[mid] == target isFirst is true ~ This implies that we are trying to find the first occurrence of the element. If mid == begin or nums[mid - 1] != target, then we return mid as the first occurrence of the target. Otherwise, we update end = mid - 1 isFirst is false ~ This implies we are trying to find the last occurrence of the element. If mid == end or nums[mid + 1] != target, then we return mid as the last occurrence of the target. Otherwise, we update begin = mid + 1 nums[mid] > target ~ We update end = mid - 1 since we must discard the right side of the array as the middle element is greater than target. nums[mid] < target ~ We update begin = mid + 1 since we must discard the left side of the array as the middle element is less than target. We return a value of -1 at the end of our function which indicates that target was not found in the array. In the main searchRange function, we first call findBound with isFirst set to true. If this value is -1, we can simply return [-1, -1]. Otherwise, we call findBound with isFirst set to false to get the last occurrence and then return the result. Time complexity : O(log n). Space complexity : O(1) #DSA #Programming #LeetCode #ProblemSolving #CodingJourney #TechCommunity
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
Nice job! Really well-explained journey from brute force to your optimized approach. Keep up the solid work! 🙌