🚀 𝗡𝗲𝘄 𝗣𝗥 𝗠𝗲𝗿𝗴𝗲𝗱 Just tackled a fun logical challenge: finding the intersection of two arrays. The goal was to identify elements present in both input arrays. I approached this using JavaScript. My strategy involved iterating through the first array and checking for the existence of each element in the second array. To optimize this lookup, I leveraged a Set data structure, which provides average O(1) time complexity for checking membership. During the 🐞 𝗗𝗲𝗯𝘂𝗴𝗴𝗶𝗻𝗴 𝗣𝗿𝗼𝗰𝗲𝘀𝘀, I found dry runs and visualizing the data flow particularly helpful. Stepping through the code with a debugger allowed me to pinpoint exactly where my logic was diverging from the expected output. A 📚 𝗞𝗲𝘆 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴 for me was the significant performance improvement gained by using a Set for lookups compared to nested loops or Array.prototype.includes within a loop. Check out the implementation and contribute to the discussion here: https://lnkd.in/dvQbUFGK How do you typically ⚙️ 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵 array intersection problems? 📦 Repo: https://lnkd.in/dvQbUFGK #Algorithm #JavaScript #ProblemSolving #DataStructures #Set #CodingChallenge #Developer #Tech #InterviewQuestion #LogicalThinking
JavaScript Array Intersection Challenge: Leveraging Sets for Efficient Lookup
More Relevant Posts
-
Built something today because nothing out there worked the way I needed. I came up with a new sorting approach — “Zipper Sort” — and wanted to visualize it step by step. Existing tools didn’t cut it (too abstract, not real execution), so I built my own 👇 🚀 ALGO_TYPEWRITER — a browser-based visualizer that runs real C/C++ sorting code and animates it live. 💡 What it does • Paste C/C++ → hit RUN • Watch comparisons (green) & swaps (bars slide, not resize) • Pause/resume, control speed, adjust array size • Get stats: time, comparisons, swaps + inferred complexity ⚙️ How it works • Regex-based transpiler → C/C++ → JS • Proxy layer logs comparisons/swaps (no code modification) • Action log replayed as smooth animations 📊 Complexity is measured empirically, not hardcoded. 🔥 Built this to test one idea… ended up building a full system. Would love to hear your thoughts on Zipper Sort and whether tools like this would help you understand algorithms better. #buildinpublic #algorithms #cpp #javascript #webdev #learningbydoing Link to the GitHub Repo housing this Project https://lnkd.in/dmdHfWQf
To view or add a comment, sign in
-
🔥 Most developers know .flat() exists. Very few know how to implement it from scratch. I just wrote a deep-dive on Flattening Nested Arrays in JavaScript — including the one approach that will impress any interviewer. Here's what's inside: → What nested arrays actually look like in memory → Why you need flattening in real projects (API responses, grouped data) → 4 different approaches: .flat(), .flatMap(), reduce + concat, recursive spread → The iterative stack approach — no recursion, no stack overflow risk → 6 common interview scenarios with the exact problem-solving mindset If you've ever written a nested forEach inside another forEach — this blog is for you. Read the full blog here 👇 🔗 https://lnkd.in/gSvQRSxi Check out my Hashnode profile 👇 🔗 https://lnkd.in/gAwxuryw hashtag #JavaScript #WebDevelopment #CodingInterview #Programming #piyushgarg #chaicode #hiteshchoudhary
To view or add a comment, sign in
-
-
Day 33: Implementing an array flattener. Focusing on the logic behind converting nested arrays into a single-dimensional structure. While JavaScript provides the flat method, writing a manual implementation using recursion helped clarify how to traverse unknown depths of data. Key takeaways: Recursion base cases: Identifying when an element is a primitive value versus another array. Method overhead: Understanding the difference between built-in methods and custom recursive functions in terms of readability and performance. Data manipulation: Practical applications in handling complex API responses where data is often deeply nested. #JavaScript #WebDevelopment #CodingJourney #Frontend #ComputerScience
To view or add a comment, sign in
-
-
Solved one of the most interesting linked list problems today: Copy List with Random Pointer. At first glance, it looks like a standard cloning problem—but the presence of a random pointer changes everything. A simple reference copy won’t work here; it requires a proper deep copy with pointer reconstruction. Key learnings: JavaScript objects are reference-based, so copying variables does not create new structures. Using a Map to store original node → cloned node simplifies pointer mapping. The problem can be broken into two clean passes: Create all nodes Reconnect next and random pointers using the map There’s also an optimized O(1) space approach using interleaving nodes. What stood out most was the importance of thinking in terms of memory structure and references, not just values. Problems like this reinforce a core principle: Understanding how data is linked is more important than just writing code that “works.” #DataStructures #LinkedList #JavaScript #ProblemSolving #SoftwareEngineering #InterviewPrep
To view or add a comment, sign in
-
-
Hot take: var isn't just outdated — it was always broken. We just didn't have anything better. I wrote a deep-dive blog post explaining exactly why modern JavaScript dropped it: 1. No block scope — variables leak outside { } blocks 2. Attaches to the global window object 3. Silent hoisting — returns undefined before declaration with zero warnings 4. Can't shadow let/const across scope boundaries 5. Forces you to write closure workarounds that let fixes in one character The post also covers the Temporal Dead Zone, the classic setTimeout loop bug, and a real code example from a closure deep-dive. If you've ever been told "just don't use var" but never understood why — this one's for you. #JavaScript #ES6 #WebDevelopment #Frontend #Programming #TechBlog
To view or add a comment, sign in
-
I built a LeetCode-style coding playground inside a browser — with zero backend. No server. No containers. No API calls. Just your browser running real Python and JavaScript. The Technical Interview Prep tool now lets you: Write and run actual code against test cases — instantly - Python runs via WebAssembly (Pyodide) — a full Python interpreter in your browser - JavaScript executes in isolated Web Workers — fast and sandboxed - 19 classic interview problems with auto-generated function stubs - Real test runners with pass/fail results, stdout capture, and execution timing Practice the way you'll be tested - Two Sum, Valid Parentheses, Binary Search, Merge Intervals — the hits are all here - Switch between Python and JavaScript with one click - See input, expected output, and your actual output side by side - Get instant feedback — no waiting for a server round-trip The guided framework that sets it apart This isn't just a code editor. Each problem walks you through a 10-step structured approach: Restate → Clarify → I/O/Constraints → Brute Force → Trade-offs → Optimal → Time O(?) → Space O(?) → Edge Cases → Reflect Pattern recognition drills, complexity quizzes, flashcards, and a mock interview timer round it out. The fun part? The hardest bug wasn't an algorithm — it was the Alpine.js DevTools Chrome extension silently blocking our Web Workers from loading. Hours of debugging CSP headers, blob URLs, and service workers... only to find a browser extension was the culprit. Link in the comments Day 34(ish) of building a tool every day for 100 days #SoftwareEngineering #InterviewPrep #WebDevelopment #Python #JavaScript #CodingInterview #TechCareers #BuildInPublic
To view or add a comment, sign in
-
-
Just solved the Binary Search problem in JavaScript. Binary Search is a great example of the Divide and Conquer approach. Instead of checking every element, the algorithm looks at the middle of a sorted array and eliminates half of the search space each step. Because the array is divided in half every time, the time complexity becomes O(log n), which makes it much faster than linear search O(n) for large datasets. Small problem, but a great reminder of how powerful algorithmic thinking can be. #JavaScript #Algorithms #BinarySearch #CodingPractice #LeetCode #SoftwareEngineering
To view or add a comment, sign in
-
JavaScript’s sort() can silently break your algorithms. I was solving LeetCode #350 (Intersection of Two Arrays II) using the two-pointer approach and hit an unexpected issue. I sorted the arrays like this: nums.sort() It looked fine… until it wasn’t. Example: [1, 2, 10, 5].sort() // → [1, 10, 2, 5] Why? Because JavaScript sorts lexicographically (as strings) by default. So the engine actually compares: "1", "10", "2", "5" Correct numeric sorting requires a comparator: nums.sort((a, b) => a - b) Without this, algorithms that rely on sorted arrays (binary search, two-pointer techniques, etc.) can produce incorrect results. #JavaScript #WebDevelopment #Programming #CodingTips #LeetCode #Algorithms #SoftwareEngineering #FrontendDevelopment
To view or add a comment, sign in
-
-
🚀 Day 9| JavaScript Today I explored JavaScript Foundations: Primitive Data Types & Operations — the building blocks of programming. 📌 Key concepts I learned: 🔹 Primitive Data Types • Number & BigInt → Used for numeric values and large integers • Boolean → Represents true or false (used in decision making) • Null & Undefined → Represent empty or uninitialized values 🔹 Operations in JavaScript • Arithmetic operations (+, -, *, /) • Logical operations (&&, ||, !) • Comparison operations (==, ===, >, <) ⚙️ I also understood how JavaScript performs computational actions to process and manipulate data effectively. 💡 Learning these fundamentals is important to build strong problem-solving skills and write efficient code. Step by step, I’m strengthening my JavaScript basics and programming logic. 💻✨ #JavaScript #WebDevelopment #FrontendDevelopment #CodingJourney #LearningInPublic #DeveloperJourney #ProgrammingBasics
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
Keep it up bro