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
Solved Valid Anagram problem using hash maps in NeetCode150
More Relevant Posts
-
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
To view or add a comment, sign in
-
-
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 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
-
DSA Practice — Day 10 Solved the “Merge Sorted Array” problem on LeetCode 🧩 At first glance, it looked simple — just merge and sort. But when I started optimizing, it turned into an interesting challenge. 🧠 My Approaches: 1️⃣ Brute Force: Directly add all elements into one array and sort. (Simple, but inefficient ) 2️⃣ Two Pointer + Extra Space: Created a copy of nums1 and merged both arrays efficiently. ➤ Time Complexity: O(m + n) ➤ Space Complexity: O(n) 3️⃣ Optimized In-Place Approach: Used two pointers starting from the end of both arrays — merging in reverse order without extra space. ➤ Time Complexity: O(m + n) ➤ Space Complexity: O(1) 💡 Lesson: The best solution often hides behind simple logic — you just have to look from the right direction. #DSA #LeetCode #ProblemSolving #JavaScript #LearningInPublic #CodingJourney #BackendDeveloper #100DaysOfCode
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 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 4 – Mastering Objects & Arrays Day 4 was all about Objects and Arrays — the backbone of JavaScript data handling. I learned how to create, modify, and loop through them efficiently. Also explored methods like map(), filter(), and reduce() — game changers for clean, readable code! 💡 Realized how these methods simplify complex logic into elegant one-liners. 💬 Which one do you use the most — map, filter, or reduce? #JavaScript #WebDevelopment #CodingChallenge #FrontendLearning #gfg #geeksforgeeks #React
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 16: Recursion Clicked Even Deeper Today Today I solved a classic problem: finding the sum of the first N numbers using recursion. To understand it better, I walked through the entire recursion tree — call by call — and observed how each function waits on the next one, and how the values return back up the stack. function sumToN(n) { if (n === 0) { return 0; } return n + sumToN(n - 1); } While tracing it manually, I followed this flow: sumToN(5) → 5 + sumToN(4) sumToN(4) → 4 + sumToN(3) sumToN(3) → 3 + sumToN(2) sumToN(2) → 2 + sumToN(1) sumToN(1) → 1 + sumToN(0) sumToN(0) → base case → returns 0 Then everything unwinds back up with the final result: 15 Today’s takeaway: Recursion becomes simple when you clearly see two things — the base case and the flow of return values in the call stack. #Recursion #JavaScript #DSA #100DaysOfCode #LearningInPublic
To view or add a comment, sign in
-
Syntax Trap #001 Hey there 👋 I've spent a lot of time learning the details of JavaScript and stumbled across lots of surprising gotchas that only became clear after understanding what's going on under the hood. I plan to post one of these each day (or so) and would love to get discussions around the specific "problems". Here's the first: What's the result? const num = '5'; console.log("5" * 4 + num); Error 25 205 55555 Easy, right :) .. said some of my coworkers, before getting it wrong 🤓 https://lnkd.in/g6KefEgc
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