Building Subsets on Day 226 Today Today is day 226 of my coding journey and I focused on solving the Power Set problem using JavaScript. This involves finding every possible combination of elements from a given array including the empty set. I used the Backtracking technique to explore all paths. The logic starts with an empty array and then adds elements one by one. After exploring a specific path I used the pop method to remove the last element. This is the unchoose step that allows the code to go back and try a different number. One important thing I practiced today is how to use the spread operator to create a copy of the current path before adding it to the result. This ensures that the final list contains the correct values instead of just references to an empty array. Understanding how recursion builds a state space tree makes solving these types of problems much clearer. I solved this LeetCode question today: LeetCode 78 Subsets #DSAinJavaScript #365daysOfCoding #JavaScriptLogic #LeetCode #BacktrackingAlgorithms #Recursion #ProblemSolving #CodingChallenge #WebDevelopment #SoftwareEngineering #DataStructures #LogicBuilding #TechLearning #JSAlgorithms #SoftwareDevelopment #CodingSkills #DailyCoding #ArrayManipulation #FullStackDeveloper #ProgrammingJourney
Day 226: Solving LeetCode 78 Subsets with JavaScript Backtracking
More Relevant Posts
-
LeetCode Day 21 : Problem 209 (Minimum Size Subarray Sum) Just solved my LeetCode problem for today. It was "Minimum Size Subarray Sum", find the shortest contiguous subarray whose sum is greater than or equal to a target. My first approach was trying to trim the array from both ends. Remove elements from the front if the sum still holds, then figure out the length at the end. It felt logical in my head but it failed on most test cases and I couldn't immediately see why. The bugs were deeper than I expected. The first one was a JavaScript gotcha that had nothing to do with the algorithm. I wrote newArr = nums thinking I was making a copy. I wasn't. Both variables pointed to the same array in memory, so when I called shift() on newArr, I was also mutating nums mid-loop. The loop was iterating over an array that was shrinking underneath it, silently skipping elements. The second issue was the trimming logic itself. I was only ever looking at the first element when deciding what to remove. That is not how you find a minimal window. You need to consider every possible left boundary, not just the front of the array at that moment. The third was a line I wrote thinking it was doing something: newArr.unshift() with no argument. It adds nothing, returns the length, and the result goes nowhere. Completely dead code that I mistook for a shrink operation. The correct approach is a dynamic sliding window. Expand the right pointer freely. The moment your window sum meets the target, record the length and shrink from the left. Keep shrinking as long as the condition still holds. The smallest window you ever record is your answer. The subtle difference from a longest-window problem is where you record the answer. Here it goes inside the shrink loop, before you remove the left element, because you want the smallest valid window not the largest. The real lesson? Mutating an array while iterating over it is one of the most silent bugs in JavaScript. Always copy with slice or spread when you need an independent array. #DSA #LeetCode #JavaScript #CodingJourney #Programming
To view or add a comment, sign in
-
-
💻 Day 1 of Coding Today I practiced JavaScript fundamentals and solved some problems: • Calculated average marks from an array • Applied 10% discount on item prices using loops • Worked with arrays (adding, removing, replacing elements) • Created functions to count vowels in a string (normal + arrow function) • Practiced if-else and loop-based questions While solving these, I did face some difficulties understanding the logic at first, but after thinking through the problems step by step, I was able to figure them out. What I learned: Better understanding of loops and arrays How to manipulate data inside arrays Writing cleaner logic step by step Small progress, but staying consistent 🚀 #JavaScript #100DaysOfCode #WebDevelopment
To view or add a comment, sign in
-
🚀 Building Strong Foundations in JavaScript 💻✨ ✨Continuing my journey of improving core JavaScript skills through hands-on coding 👇 🔹 Loops Practice ✅ Printed numbers from 1–50 using: • for loop • while loop • do...while loop 🔹 Logic Building ✅ Generated multiplication table dynamically using user input 🔹 Iteration Techniques ✅ Used for...of for arrays and for...in for objects 🔹 Functions Practice ✅ Built a function to check Prime or Non-Prime numbers ✅ Implemented a Callback Function to calculate square of a number ✅ Practiced IIFE (Immediately Invoked Function Expression) to print today’s date 💡 Key Learnings: • Better understanding of loops and iteration • Clear idea of callback & higher-order functions • Debugged a real issue with IIFE and semicolons 😄 📌 Step by step, improving logic and confidence in JavaScript! #JavaScript #CodingJourney #LearningByDoing #FrontendDeveloper #WebDevelopment #KeepGrowing 🚀
To view or add a comment, sign in
-
Ever felt like your functions could be more flexible and reusable? 🤔 That’s where currying in JavaScript comes in! Instead of passing all arguments at once, currying transforms a function into a sequence of functions — each taking a single argument. ✨ Why it matters: • Improves code reusability • Encourages cleaner, modular design • Makes function composition easier 🔍 Example: const add = a => b => a + b; Now you can do: const add5 = add(5); add5(3); // 8 Small change, big impact 💡 If you're diving deeper into functional programming, currying is definitely a concept worth mastering. #JavaScript #WebDevelopment #FunctionalProgramming #CleanCode #100DaysOfCode
To view or add a comment, sign in
-
-
Closures in JavaScript felt confusing, until they didn’t 👇 At first, it’s hard to understand how a function can “remember” variables even after execution. But that’s exactly what closures do. A closure is created when a function retains access to its lexical scope, even after the outer function has finished executing. Even though `outer()` has finished execution, the inner function still has access to `count`. That’s the power of closures. They are widely used for: • Data encapsulation • Maintaining state • Creating reusable functions Understanding closures makes many JavaScript patterns much clearer. #JavaScript #Closures #FrontendDevelopment #SoftwareEngineering #Programming
To view or add a comment, sign in
-
-
🚀 Diving into Arrays: Master the Basics of Array Iteration in JavaScript 🌟 Arrays may seem complex, but they're just collections of data stored in a single variable. As a developer, understanding array iteration is crucial for processing and manipulating data efficiently in your projects. 💡 Let's break it down step by step: 1️⃣ Create an array 2️⃣ Use a loop to iterate through each element 3️⃣ Perform actions on each element within the loop. 🖥️ Check out the code snippet below for a hands-on example: ```javascript const myArray = [1, 2, 3, 4, 5]; myArray.forEach((element) => { console.log(element); }); ``` 🔧 Pro Tip: Utilize array methods like forEach, map, or filter for different iteration purposes. 🚫 Common Mistake: Forgetting to define the function inside array methods like forEach. Have you ever struggled with array iteration in your projects? Share your experiences below! 🌐 View my full portfolio and more dev resources at tharindunipun.lk #JavaScript #ArrayIteration #WebDevelopment #CodingTips #Programming #JSArray #DeveloperCommunity #TechTalk #CodeNewbie
To view or add a comment, sign in
-
-
🚀 Day 7 / 30 - JavaScript Coding Practice Today’s challenge: Recreating the Array.map() functionality — without actually using it 👀 Problem: Apply a transformation function to each element of an array and return a new array. 💡 Key Insight: This problem helped me understand what’s happening under the hood of built-in methods like map(). 👉 Instead of relying on .map(), I used a loop to: Iterate through each element Apply the given function with both value & index Build a new transformed array Solution: var map = function (arr, fn) { let transArr = [] arr.forEach((element, i) => { transArr.push(fn(element, i) ?? element); }); return transArr; }; #JavaScript #DSA #CodingPractice #100DaysOfCode #FrontendDevelopment #ProblemSolving
To view or add a comment, sign in
-
-
Leetcode Day 1 : Problem 1 (Merge Sorted Array) Just solved my first LeetCode problem. It was the classic "Merge Sorted Array" sounds simple, right? But here's what I actually learned: JavaScript's .sort() doesn't sort numbers by default, it sorts them as strings. [1, 10, 2] becomes [1, 10, 2] not [1, 2, 10]. A one-line bug that would fail silently. Reassigning an array variable (arr = []) doesn't modify the original. LeetCode wants in-place changes. That took me a moment. I was filtering out zeros thinking they were empty slots, but 0 is a perfectly valid element. Hidden test cases would've caught me. Three bugs. One "easy" problem. Tons of learning. The real lesson? Passing the visible test cases doesn't mean your code is correct. Always think about edge cases. If you've been putting off starting DSA Interview questions like I was just open problem 1 and start. The first step is the hardest. #DSA #LeetCode #JavaScript #CodingJourney #Programming
To view or add a comment, sign in
-
-
#Day15 Mastering Callbacks in JavaScript Today let’s talk on Callbacks a core concept for handling asynchronous operations in JavaScript. At Mentorship for Acceleration for backend track, I explored how callbacks allow functions to execute after tasks like timers, events, or API responses complete. I also saw firsthand why they can lead to “Callback Hell” if not managed well. Key Concepts Practiced: => Basic callback implementation with setTimeout() => Using callbacks with array methods (.map(), .forEach(), .filter()) => Named vs anonymous callback functions => Understanding the limitations of nested callbacks Callbacks have sharpened my understanding of asynchronous programming and prepared me for cleaner patterns like Promises. Progressing steadily! #M4ACELearningChallenge #LearningInPublic #JavaScript
To view or add a comment, sign in
-
-
Today I explored more concepts in JavaScript and practiced hands-on coding. Topics I covered: ✔️ Variables (let, const) ✔️ Dynamic typing in JavaScript ✔️ Objects (creating, accessing, updating) ✔️ Adding new properties to objects ✔️ Functions inside objects (methods) 💡 Key Takeaway: JavaScript objects are very powerful for storing and managing real-world data, and understanding them is essential for working with APIs and building applications. 📸 Sharing some practice screenshots below. Next Step → Arrays and more real-world examples 🔥 #javascript #webdevelopment #codingjourney #mern #learning
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