Day 4 of #100DaysOfNeetCode | #NeetCode150 Today’s challenge was the classic Three Sum problem, one that tests sorting, two-pointer logic, and careful duplicate handling. Three Sum -> Goal: Find all unique triplets in the array which sum up to zero. -> Brute Force: Use three nested loops to check every triplet. This works but runs in O(n³), making it inefficient for larger inputs. -> Optimized: Sort the array first. Fix one number and then use the two-pointer approach to find pairs that make the total zero. Skip duplicate numbers to avoid repeating triplets. Time Complexity: O(n²) Key idea: Sorting plus the two-pointer method helps efficiently reduce complexity while managing duplicates gracefully. Example: nums = [-1, 0, 1, 2, -1, -4] → Output: [[-1, -1, 2], [-1, 0, 1]] Takeaway: Sorting combined with pointer movement is a powerful approach for problems involving sums within an array. #Day4 #JavaScript #LeetCode #NeetCode150 #DSA #ProblemSolving #100DaysOfNeetCode #CodingJourney
Solving Three Sum with Sorting and Two Pointers
More Relevant Posts
-
Day 6 of #100DaysOfNeetCode | #NeetCode150 Today I worked on the Valid Parentheses problem — a classic question that tests stack operations and understanding of string parsing logic. Valid Parentheses -> Goal: Determine if a string containing only '(', ')', '{', '}', '[' and ']' is valid. A valid string must have matching and correctly ordered brackets. -> Brute Force: Repeatedly remove pairs like (), {}, [] until no more replacements can be made. Return true if the string becomes empty. Time Complexity: O(n²) due to multiple passes. -> Optimized: Use a stack to push opening brackets and pop them when a valid closing match appears. Use a map to pair closing brackets with their corresponding openings. Return true if the stack is empty at the end. Key idea: The stack ensures last opened brackets are closed first (LIFO). Example: str = "()" → Output: true str = "([{}])" → Output: true str = "(]" → Output: false Time Complexity: O(n) Takeaway: Stack-based approaches are powerful for problems involving nested or sequentially dependent structures. #Day6 #JavaScript #LeetCode #NeetCode150 #DSA #ProblemSolving #100DaysOfNeetCode #CodingJourney
To view or add a comment, sign in
-
-
Day 8 of #100DaysOfNeetCode | #NeetCode150 Today I solved the Valid Anagram problem — a fundamental string question that focuses on frequency counting and efficient comparison. 1. Valid Anagram -> Goal: Determine if two strings are anagrams, meaning one string can be formed by rearranging the letters of the other. -> Brute Force: Sort both strings and compare them directly. Simple but has a time complexity of O(n log n+ m long m). -> Optimized: Use two hash maps to count the frequency of each character in both strings, then compare their counts. If every character frequency matches, the strings are anagrams. Key idea: Counting frequencies eliminates the need for sorting, reducing time complexity. Example: s = "racecar", t = "carrace" → Output: true s = "hello", t = "bello" → Output: false Time Complexity: O(n), Space: O(1) (constant alphabet size) Takeaway: Hash maps are a powerful tool for counting and comparing elements efficiently, a concept that extends to many string and array problems. #Day8 #JavaScript #LeetCode #NeetCode150 #DSA #ProblemSolving #100DaysOfNeetCode #CodingJourney
To view or add a comment, sign in
-
-
🌟 Day 22 of #100DaysOfDSA Today, I solved two interesting problems: 1️⃣ Reverse a Linked List Reversed a singly linked list by iteratively changing the node pointers. Time Complexity: O(n) Space Complexity: O(1) 2️⃣ Move Zeroes Rearranged all zeroes in an array to the end while maintaining the order of non-zero elements — done in-place with linear time. Time Complexity: O(n) Space Complexity: O(1) Both problems were great practice for improving logical thinking and working efficiently with pointers and arrays. https://lnkd.in/gt7VYQ_E #100DaysOfCode #DSA #JavaScript #CodingJourney #LearningInPublic #LeetCode
To view or add a comment, sign in
-
Day 3 of #30DaysOfJavaScript on LeetCode Today's challenge: 2704 — To Be Or Not To Be The task was to create a custom expect function that helps test code logic — much like how assertion libraries work in testing frameworks. Here’s my solution 👇 var expect = function(val) { return { toBe: function(otherVal) { if (val === otherVal) return true; else throw new Error("Not Equal"); }, notToBe: function(otherVal) { if (val !== otherVal) return true; else throw new Error("Equal"); } }; }; This challenge was a nice introduction to function objects and error handling in JavaScript — building a mini testing utility was fun! 💡 If you’d like to give it a shot, check it out here: https://lnkd.in/g6WC5mu7 #JavaScript #LeetCode #CodingChallenge #LearningJourney #Closures #30DaysOfCode #ErrorHandling #Testing
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
-
Tired of repetitive object.property syntax? ✨ Let's talk destructuring! Tip #009: Use object destructuring to extract multiple properties from objects in a single, clean statement. Perfect for function parameters, API responses, and config objects. Benefits: ✅ Cleaner, more readable code ✅ Less repetition ✅ Better parameter naming ✅ Modern JavaScript standard What's your favorite use case for destructuring? Share your examples below! 👇 #JavaScript #CleanCode #WebDevelopment #ProgrammingTips #SoftwareEngineering #Coding #ModernJavaScript #100Devs #Developer
To view or add a comment, sign in
-
-
Day 23/90 – 90 Days DSA Challenge Today I practiced another classic recursion problem — Sum of first N natural numbers using recursion 💡 🧠 Concept Recap: Recursion is when a function calls itself with a smaller input until it reaches a base condition. It’s like peeling an onion layer by layer — until you reach the core 🧅 ⚙️ Problem Statement: 👉 Write a function sum(n) that calculates the sum of the first n natural numbers. 🧩 Example: Input: 5 Process: 5 + 4 + 3 + 2 + 1 = 15 Output: 15 Time Complexity: O(n) 💾 Space Complexity: O(n) (due to call stack) ✨ Key takeaway: Recursion helps break down complex problems into smaller, simpler ones — it’s elegant, powerful, and mind-opening once you get the hang of it! #Day23 #DSA #Recursion #JavaScript #CodingChallenge #MechCode #LearningInPublic #FrontendDeveloper #CodeEveryday
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
-
-
DSA Practice — Day 7 Solved the “Remove Duplicates from Sorted Array” problem on LeetCode. 🧩 Approach: • First, understood the problem statement clearly. • Analyzed the given examples and patterns. • Performed a dry run on paper to visualize the algorithm. • Implemented a pointer-based approach to remove duplicates efficiently. “Clarity before code — that’s how you build problem-solving discipline.” #DSA #LeetCode #ProblemSolving #JavaScript #LearningInPublic #CodingJourney #BackendDeveloper
To view or add a comment, sign in
-
-
Instead of const result = sanitize(validate(capitalize(truncate(trim(userInput)) )); which is nested, unreadable, and hard to debug, with a simple reusable pipe like the one below we can have const cleanTitle = pipe(trim,truncate,capitalize, validate,sanitize); const result = cleanTitle(userInput); which is declarative and reads like a story. For dig into more tips like these check functional programming arena in Javascript -> https://lnkd.in/d8XurWWs #JavaScript #SoftwareEngineering #SoftwareDevelopment #Coding #100DaysOfCode #FunctionalProgramming #DeclarativeProgramming #MaintainableCode
To view or add a comment, sign in
-
More from this author
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