LeetCode: Longest Consecutive Sequence ✅ This problem real challenge is beating the naïve sorting approach. Strategy: Instead of sorting, I used a HashSet for constant-time lookups. The key idea is to only start counting a sequence when the current number does not have a predecessor (num - 1). From there, expand forward to count the full streak. This ensures every number is visited only once. 🕒 Time Complexity: O(n) — each element is processed at most once 📦Space Complexity: O(n) — extra space for the set 👉 The right data structure often matters more than clever loops. #LeetCode #DSA #JavaScript #ProblemSolving #LearnInPublic #CodingJourney #CSwithDev
Devesh Shukla’s Post
More Relevant Posts
-
Balance a Binary Search Tree Using Inorder Traversal 👉 Day 87 / Day 93 👈 36 🔥 Key Points 👉 Inorder traversal guarantees sorted node values for a BST 👉 Choosing the middle element ensures height balance 👉 Recursive construction creates a balanced BST 👉 Time Complexity: O(n) 👉 Space Complexity: O(n) (for storing traversal result and recursion stack) #JavaScript #TypeScript #DataStructures #Algorithms #BinarySearchTree #Trees #DSA #CodingInterview #ProblemSolving #Recursion #LeetCode #SoftwareEngineering #FrontendDevelopers
To view or add a comment, sign in
-
-
From Sorted Data to Balanced Trees: Divide, Conquer, Balance 🌳 Solved LeetCode 108 - Convert Sorted Array to Binary Search Tree today. The solution clicked by treating the array like a search space: -Pick the middle element as the root -Recursively build the left half and right half -Stop when the range becomes invalid This guarantees a height-balanced BST without extra work. Key takeaway: Balanced trees are a natural outcome of divide-and-conquer. Choosing the midpoint at every step keeps depth under control. Strengthening recursive thinking and tree intuition. #LeetCode #DSA #BinarySearchTree #Recursion #DivideAndConquer #JavaScript #ProblemSolving #LearnInPublic
To view or add a comment, sign in
-
𝗪𝗲𝗹𝗰𝗼𝗺𝗲 𝘁𝗼 𝗗𝗮𝘆 𝟮𝟬 What if you could control every interaction with an object — reads, writes, deletes — without changing the object itself? That’s what Proxy does. 𝘼 𝙋𝙧𝙤𝙭𝙮 𝙞𝙨 𝙖 𝙬𝙧𝙖𝙥𝙥𝙚𝙧 𝙖𝙧𝙤𝙪𝙣𝙙 𝙖𝙣 𝙤𝙗𝙟𝙚𝙘𝙩 𝙩𝙝𝙖𝙩 𝙞𝙣𝙩𝙚𝙧𝙘𝙚𝙥𝙩𝙨 𝙡𝙤𝙬-𝙡𝙚𝙫𝙚𝙡 𝙤𝙥𝙚𝙧𝙖𝙩𝙞𝙤𝙣𝙨 𝙡𝙞𝙠𝙚: -> Property access -> Property assignment -> Property deletion -> Function calls -> Object construction 𝙄𝙣𝙨𝙩𝙚𝙖𝙙 𝙤𝙛: Engine → Object 𝙄𝙩 𝙗𝙚𝙘𝙤𝙢𝙚𝙨: Engine → Proxy → Object The Proxy decides what happens. 𝙒𝙝𝙮 𝙄𝙩 𝙈𝙖𝙩𝙩𝙚𝙧𝙨: 𝙋𝙧𝙤𝙭𝙮 𝙡𝙚𝙩𝙨 𝙮𝙤𝙪 𝙘𝙤𝙣𝙩𝙧𝙤𝙡 𝙗𝙚𝙝𝙖𝙫𝙞𝙤𝙧, 𝙣𝙤𝙩 𝙟𝙪𝙨𝙩 𝙙𝙖𝙩𝙖. You can: -> Validate values before saving -> Block unknown properties -> Log every change -> Create computed/virtual properties 𝘛𝘩𝘦 𝘰𝘣𝘫𝘦𝘤𝘵 𝘴𝘵𝘢𝘺𝘴 𝘵𝘩𝘦 𝘴𝘢𝘮𝘦. 𝘛𝘩𝘦 𝘪𝘯𝘵𝘦𝘳𝘢𝘤𝘵𝘪𝘰𝘯 𝘳𝘶𝘭𝘦𝘴 𝘤𝘩𝘢𝘯𝘨𝘦. #JavaScript #JSInternals #FrontendEngineering #WebDevelopment #SoftwareEngineering #ECMAScript #MetaProgramming #FrontendArchitecture #TechDeepDive #Coding
To view or add a comment, sign in
-
-
🚀 Cracked a tricky DSA concept today — Search in Rotated Sorted Array (with duplicates) At first glance the array looks unsorted… But actually it’s two sorted arrays joined together 🔍 Example: [2,5,6,0,0,1,2] The challenge ❓ Find a target efficiently (not O(n)) → Use Modified Binary Search (O(log n)) 💡 Key Learning: 1️⃣ One half of the array is always sorted 2️⃣ Check if target lies in the sorted half 3️⃣ If duplicates confuse the search → shrink the window (left++, right--) Core logic: • All equal → ignore edges • Left sorted → search there • Else → search right side 📈 What I learned: Understanding the logic is more important than memorizing code. Today I didn’t just solve a problem — I understood how to think like an algorithm. #DSA #BinarySearch #JavaScript #CodingJourney #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
🚨 "Cannot read properties of undefined" in production. 🚨 Have you ever been frustrated to fix this error in minified & obfuscated code? Unfortunately, you can’t enable source maps in production — but don’t worry, I’ve got you covered. In my latest article, I walk you through step-by-step ways to debug this error, even in fully minified code. All you need is the stack trace. And trust me, it isn't just about adding a "?" everywhere. 👀 The article covers: ✅ Decoding stack traces and reverse engineering the execution path back to the root cause. ✅ Identifying the internal symbols and what they represent. ✅ Implementation of defensive coding patterns that actually work to avoid such issues in production. #webdevelopment #angular #javascript #typescript #debugging #cleancode #coding
To view or add a comment, sign in
-
🚀 LeetCode Problem Solved – Sort Characters by Frequency Today I solved the “Sort Characters By Frequency” problem on LeetCode. 🔎 Problem Statement: Given a string, sort its characters in decreasing order based on their frequency. 🧠 Key Learning: Instead of directly sorting the string (which isn’t possible since strings are immutable in JavaScript), I: ✔ Counted the frequency of each character using an object ✔ Extracted keys using Object.keys() ✔ Sorted them based on frequency (descending order) ✔ Rebuilt the final string using nested loops 💡 Concepts Used: HashMap / Object for frequency counting Custom sorting with comparator function String building using loops Time Complexity optimization thinking ✨ Example: Input: "tree" Output: "eert" This problem strengthened my understanding of: Frequency-based sorting Custom comparator logic Clean DSA implementation in JavaScript Consistency in solving DSA problems daily 🚀 #LeetCode #DSA #JavaScript #ProblemSolving #CodingJourney #FrontendDeveloper #100DaysOfCode
To view or add a comment, sign in
-
-
Javascript arrays are more powerful than you think. 🚀 I used to write complex for loops for data manipulation. Then I truly understood the power of array methods. It’s not just about shorter code—it’s about readability and intent. Three underused methods that deserve more love: .some(): Checks if at least one element passes a test. Great for validation. .every(): Checks if all elements pass. Perfect for form checking. .reduce(): The Swiss Army knife. From summing numbers to reshaping entire data structures. Clean code isn't about being clever; it's about making your logic obvious to the next developer who reads it (which is usually you, six months later). Which array method do you find yourself using the most? #JavaScript #Coding #SoftwareEngineering #WebDev #CleanCode
To view or add a comment, sign in
-
📌 #53 DailyLeetCodeDose Today's problem: 71. Simplify Path – 🟡 Medium These are the kinds of problems you'll most likely face. They aren't difficult, but they're quite practical. Such tasks don't require knowledge of sophisticated algorithms or complex data structures, yet they appear quite often in real-world development, so practicing them is definitely useful. https://lnkd.in/e7BpT3JP #DailyLeetCodeDose #LeetCode #JavaScript #Algorithms #ProblemSolving #Coding
To view or add a comment, sign in
-
-
Hii Folks 🙂 Yesterday, while discussing the JavaScript Event Loop with a senior, I realized something important. Most of us explain the Event Loop using queues and the call stack. That explanation is correct, but it’s incomplete. It answers how things run, not why they behave the way they do. The deeper question came up: Before the Event Loop even starts scheduling tasks, how does JavaScript know what those tasks are allowed to access? That’s where concepts like the compiler and lexical scope quietly enter the picture. JavaScript first reads the code and builds an understanding of it. Variable scope, function boundaries, and memory references are decided before execution begins. This is not the Event Loop’s responsibility. The Event Loop only works with what already exists. Lexical scope determines which variables belong to which functions. Closures decide what stays in memory even after a function finishes. None of this is created by the Event Loop, but all of it affects how async code behaves later. Data structures play a similar hidden role. The call stack is just a stack. Task queues are just queues. The scope chain behaves like a linked structure. The Event Loop doesn’t interpret logic. It simply moves execution between these structures based on a few strict rules. That discussion made one thing clear to me: If we don’t understand compiler behavior, lexical scoping, and basic data structures, the Event Loop will always feel confusing or “magical”. Async issues are rarely caused by the Event Loop itself. They usually come from misunderstanding scope, memory, or execution order. Once you see the Event Loop as a coordinator rather than a decision-maker, a lot of confusion disappears. #JavaScript #EventLoop #LexicalScope #Closures #AsyncProgramming #WebDevelopment #FrontendDevelopment #BackendDevelopment #FullStackDeveloper #SoftwareEngineering #ComputerScience #ProgrammingConcepts #DataStructures #DeveloperLearning #LearningInPublic #TechDiscussions #DeveloperCommunity #CodingLife #Debugging #EngineeringMindset #TechCareers
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