🚀 Day 88 of #100DaysOfLeetcode 🧩 Problem: Next Smaller Element You are given an array of integers, and for each element, you need to find the next smaller element to its right. If none exists, return -1. 💡 Example: arr = [2, 3, 1] → Output: [1, 1, -1] Because for 2 → next smaller is 1, for 3 → next smaller is 1, and for 1 → none smaller → -1. 🧠 Brute Force Approach Logic: For every element, traverse the elements to its right and find the first smaller one. Code Complexity: ⏱ Time Complexity: O(n²) – two nested loops 💾 Space Complexity: O(1) – no extra space used ⚙️ Optimal Approach (Using Stack) Logic: We iterate from right to left while maintaining a stack to keep track of potential smaller elements. Pop elements from the stack while the top is greater or equal to the current element. The top of the stack after popping gives the next smaller element. Push the current element into the stack for future comparisons. Code Complexity: ⏱ Time Complexity: O(n) – each element is pushed and popped once 💾 Space Complexity: O(n) – stack used for storing elements 🧮 Key Learnings: Stack-based problems often involve processing from right to left. Understanding Monotonic Stack pattern helps solve many similar problems like “Next Greater Element” and “Stock Span”. Helps in real interview scenarios where time optimization is key. ⚠️ Edge Cases: All elements in increasing order → Output will be all -1s. All elements in decreasing order → Each next element will be the answer for previous one. Single element array → Output should be -1. 💬 Final Thought: Learning the concept of Monotonic Stack not only simplifies the solution but also builds intuition for multiple real-world stack-based interview questions. 🔥 #100DaysOfCode #Leetcode #DSA #Stack #JavaScript #CodingChallenge #ProblemSolving #TechCommunity #LearningNeverStops #ProgrammingJourney #CodeNewbie #FrontendDeveloper #DataStructuresAndAlgorithms
Anurag Singh’s Post
More Relevant Posts
-
🔥 DEVELOPER CHALLENGE - 3: The “Undefined Madness” Test! Only the bravest devs dare to enter this one 👀 The Challenge: Write a one-line function that returns true if two objects have identical values (deep equality) — without using JSON.stringify(), lodash, or any external library. Example: Input: a = { x: 1, y: { z: 2 } } b = { x: 1, y: { z: 2 } } Output: true The Twist: If your code breaks for nested objects, arrays, or null values — you lose 😈 Rules: - One line only (no cheating with semicolons!) - No JSON tricks, no _.isEqual() - Must handle nested structures and edge cases - Bonus: Works in O(n) Think you’re a code ninja? Drop your solution below. Let’s see who can write the cleanest, deadliest one-liner. Tag your smartest developer friend — or your biggest bug maker #CodingChallenge #DeveloperChallenge #TopSkyll #SoftwareDevelopment #CodeChallenge #JavaScript #ProblemSolving #DevLife #TechChallenge #ProgrammingLife #AlgorithmChallenge #CodeNewbie #FullStackDeveloper #SoftwareEngineering #FridayChallenge #TechCommunity #LearnToCode #CodingPuzzle #WebDevelopment #DeveloperCommunity #TopSkyllChallenge
To view or add a comment, sign in
-
🎯 Day 172 of #200DaysOfCode Today’s challenge was all about finding all pairs in an array whose sum equals a given target number — a classic logic-building problem that strengthens both your thinking pattern and problem-solving flow. 💡 While most developers would jump to use built-in methods or advanced structures, I implemented it manually using nested loops — because fundamentals matter the most. 📘 Concepts reinforced today: • Nested loop logic • Pair combination generation • Conditional validation • Edge case handling (no valid pairs found) 🌍 Real-world use cases: ✅ Matching data pairs (like prices or scores) ✅ Detecting patterns in datasets ✅ Implementing basic algorithmic logic for interviews 🔥 The beauty of coding lies in building clarity — not just functionality. Every problem solved sharpens your analytical edge! #JavaScript #172DaysOfCode #ProblemSolving #LearnInPublic #WebDevelopment #CodingChallenge #LogicBuilding #BackToBasics #DeveloperMindset
To view or add a comment, sign in
-
-
📘 Day 175 of #200DaysOfCode Today, I explored how to count the number of properties in a JavaScript object — a small but meaningful step toward understanding how objects truly work under the hood. 🧠 Key Concepts Practiced • Working with objects • Looping through keys using for...in • Using hasOwnProperty() to avoid inherited keys • Returning calculated output 🌍 Real-World Uses ✅ Validating form inputs ✅ Checking JSON response structures ✅ Data integrity checks ✅ Object analysis in APIs 🔎 Learning takeaway: Even the simplest operations help you develop a deeper understanding of core JavaScript behavior. Mastering the fundamentals builds confidence for tackling complex problems later. #JavaScript #Day175 #175DaysOfCode #ProblemSolving #CodingChallenge #WebDevelopment #LogicBuilding #BackToBasics #LearnInPublic #DeveloperJourney #CodingMindset
To view or add a comment, sign in
-
-
🧠 Day 20 of #100DaysOfDSA Today I practiced two classic problems from LeetCode — FizzBuzz and Reverse String. 📘 What I learned: These might look like simple problems, but they help sharpen logic building, loops, and condition handling — essential building blocks for bigger challenges. 💻 Problems Solved: 1️⃣ FizzBuzz – A fun way to practice modular arithmetic and condition prioritization. 2️⃣ Reverse String – Implemented using the two-pointer approach for an in-place reversal. 💡 Key Takeaways: FizzBuzz reinforces thinking through branching logic. The two-pointer method is efficient for array and string manipulation. Small problems like these build the foundation for complex algorithms. 🔗 Check out my implementations here: https://lnkd.in/gxs9yaen #100DaysOfCode #DSA #LeetCode #JavaScript #CodingJourney #ProblemSolving #LearningInPublic
To view or add a comment, sign in
-
𝐓𝐲𝐩𝐞𝐒𝐜𝐫𝐢𝐩𝐭 𝐁𝐚𝐬𝐢𝐜𝐬 𝐟𝐨𝐫 𝐀𝐮𝐭𝐨𝐦𝐚𝐭𝐢𝐨𝐧 𝐓𝐞𝐬𝐭𝐞𝐫𝐬 – 𝐃𝐚𝐲 𝟖 𝐓𝐨𝐩𝐢𝐜: Jumping Statements in TypeScript Jumping statements let your code skip or stop parts of execution — helping control the flow inside loops and functions. In this session, we covered: 🔹 𝐛𝐫𝐞𝐚𝐤 – stops the loop or switch immediately 🔹 𝐜𝐨𝐧𝐭𝐢𝐧𝐮𝐞 – skips the current iteration and moves ahead 🔹 𝐫𝐞𝐭𝐮𝐫𝐧 – exits a function and sends a value back Includes syntax, automation-based examples (like skipping broken links or returning test results), and a clear breakdown of data type vs return type. 📘 Full notes, code examples and Q&A below 👇 #TypeScript #AutomationTesting #LearningSeries #Coding #JavaScript
To view or add a comment, sign in
-
🔥 𝐓𝐲𝐩𝐞𝐬 𝐢𝐧 𝐓𝐲𝐩𝐞𝐒𝐜𝐫𝐢𝐩𝐭: 𝐃𝐨 𝐘𝐨𝐮 𝐑𝐞𝐚𝐥𝐥𝐲 𝐊𝐧𝐨𝐰 𝐓𝐡𝐞𝐦 𝐀𝐥𝐥? TypeScript gives us superpowers, but how well do we really understand the types behind the magic? Let’s go beyond “number” and “string” and explore the real foundation of TypeScript’s type system. • Primitive types: number, string, boolean, bigint, symbol, null, undefined • Object types: objects, arrays, functions, classes, interfaces • Union types: combine multiple possible types into one flexible definition • Intersection types: merge multiple types into a single, stronger contract • Literal types: restrict values to a specific constant (like "on" or "off") • Tuple types: define arrays with fixed positions and known element types • Enum types: create a clear set of named constants • Any, unknown, never: the “dark side” of typing, powerful but dangerous if misused Here’s the key question: how do you decide which type to use when modeling real-world data? Do you rely more on interfaces, or do you prefer type aliases? Have you experimented with conditional or mapped types to make your code self-evolving? The beauty of TypeScript is not only in catching bugs early, but in shaping how we think about data and behavior. So next time you write a type, ask yourself: “Am I defining this because the compiler needs it or because my future self will thank me for the clarity?” #TypeScript #JavaScript #WebDevelopment #SoftwareEngineering #Coding #DevCommunity #TypeSafety #Programming #TechLeadership #CleanCode
To view or add a comment, sign in
-
-
It’s not always the complex algorithms that break systems , sometimes it’s a single misplaced string. The smallest things in code often make the biggest impact. That’s the difference between something that works and something that’s well-engineered. I wrote a short blog about one of those small but important habits avoiding “magic strings” in code. 🪄 “The Problem with Magic Strings - and How to Avoid Them” Read it here 👉 https://lnkd.in/gQUBC3TS #CleanCode #SoftwareEngineering #JavaScript #CodingBestPractices #DeveloperMindset #Maintainability
To view or add a comment, sign in
-
If you’ve ever tried to 𝗺𝗮𝘀𝘁𝗲𝗿 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗳𝘂𝗻𝗱𝗮𝗺𝗲𝗻𝘁𝗮𝗹𝘀 𝗱𝗲𝗲𝗽𝗹𝘆, you probably know how confusing it can get with half-baked tutorials and shallow videos. After exploring tons of resources, I’ve found the 𝗺𝗼𝘀𝘁 𝗱𝗲𝘁𝗮𝗶𝗹𝗲𝗱 𝗝𝗦 𝗽𝗹𝗮𝘆𝗹𝗶𝘀𝘁 𝗼𝗻 𝗬𝗼𝘂𝗧𝘂𝗯𝗲 — the legendary Namaste JavaScript series 🎥 by Akshay Saini 🚀. It explains JavaScript from the ground up — how the engine works, memory, hoisting, closures, TDZ, event loop — everything! But here’s the catch 👀 The playlist is long — and if you’re someone who prefers quick revision or written notes, it can be hard to go through all 20+ episodes again. Good news — I found a 𝗚𝗶𝘁𝗛𝘂𝗯 𝗿𝗲𝗽𝗼𝘀𝗶𝘁𝗼𝗿𝘆 📘 that summarizes every episode beautifully, so you can 𝗹𝗲𝗮𝗿𝗻, 𝗿𝗲𝘃𝗶𝘀𝗲, 𝗼𝗿 𝗽𝗿𝗲𝗽 𝗳𝗼𝗿 𝗶𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄𝘀 without rewatching the entire series! 💡 𝗧𝗼𝗽𝗶𝗰𝘀 𝗖𝗼𝘃𝗲𝗿𝗲𝗱 💥 Season 1 1️⃣ Execution Context 2️⃣ How JS is executed & Call Stack 3️⃣ Hoisting (variables & functions) 4️⃣ Functions & Variable Environments 5️⃣ Shortest JS Program, window & this 6️⃣ undefined vs not defined 7️⃣ Scope Chain, Scope & Lexical Environment 8️⃣ let & const, Temporal Dead Zone 9️⃣ Block Scope & Shadowing 🔟 Closures Bonus: Callback Hell, Event Loop, Higher-Order Functions, map, filter, reduce, etc. 💬 𝗖𝗼𝗺𝗺𝗲𝗻𝘁 “𝗚𝗶𝘁𝗛𝘂𝗯” and I’ll share the repository link in your DMs. 🧠 Perfect for: • Interview prep • JS concept revision • Deep understanding of the language you use daily 🎯 Credit: • Akshay Saini 🚀 (for the incredible playlist) • Alok Raj (for the GitHub summary repo) #JavaScript #WebDevelopment #Frontend #Learning #Developers #NamasteJavaScript #CodingCommunity #TechLearning #AkshaySaini #JSDeepDive #SoftwareEngineering #Programming #100DaysOfCode
To view or add a comment, sign in
-
-
Finding the First Bad Version A Binary Search Twist 👉 Day 12 / Day 93 👈 👉 Ever wondered how product managers could find the first faulty release among thousands of product versions — without checking every single one? 👉 That’s what the “First Bad Version” problem teaches us — an elegant use of binary search to minimize checks and find where things first went wrong. 👉 By halving the search space each time, we reduce the problem from O(n) to O(log n) — just like tracking a software bug down to its first breaking commit. #BinarySearch #JavaScript #ProblemSolving #LeetCode #CodingJourney #SoftwareEngineering #Debugging #TechLearning
To view or add a comment, sign in
-
-
🚀 Day 82 of #100DaysOfCode Today I learned to create an object literal in JavaScript to model a Thread/Twitter post. By organizing properties like username, content, likes, reposts, and tags into a single object, it becomes easy to manage and update social media data! Example: const post = { username: "coder123", content: "Excited to share my #100DaysOfCode progress!", likes: 120, reposts: 15, tags: ["coding", "javascript", "learning"] }; Object literals make real-world data handling simple and powerful in code. #JavaScript #ObjectLiterals #SocialMedia #Coding #100DaysOfCode
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