📅 Day 40 of #100DaysOfCode 💻 Problem: 1002. Find Common Characters Approach: 1️⃣ Start by counting the frequency of each character from the first word using a HashMap. 2️⃣ Then, for each next word, update that HashMap to store the minimum frequency of each character (since we only care about characters that appear in all words). 3️⃣ Finally, collect all characters that have a frequency greater than 0 — those are the common ones across every word. This works like a "character intersection" — reducing counts each time until only the common ones remain. #100DaysOfCode #LeetCode #DSA #ProblemSolving #Cplusplus #CodingChallenge #Algorithms #DeveloperLife #CodingJourney #KeepLearning #TechCommunity #SoftwareEngineering #Motivation
"Day 40: Finding Common Characters with HashMap"
More Relevant Posts
-
📅 Day 36 of #100DaysOfCode Today’s challenge was one of the most interesting and tricky recursion problems! Problem: Regular Expression Matching (LeetCode #10) 🔍 Approach: The goal is to determine if a given string text matches a pattern that includes: . → Matches any single character * → Matches zero or more occurrences of the preceding element 1️⃣ Used recursion to check character-by-character matches. 2️⃣ For each step: Checked if the current characters match (text[0] == pattern[0] or pattern[0] == '.'). If the next pattern character is *, explored two possibilities: Skip * and the previous character (zero occurrence). Use * to match one or more occurrences (consume one character from text). 3️⃣ Continued recursively until the entire text and pattern were checked. #100DaysOfCode #LeetCode #DSA #ProblemSolving #Cplusplus #CodingChallenge #Algorithms #Programming #DeveloperLife #CodeNewbie #DailyDSA #SoftwareEngineering #CodingJourney #LearningInPublic #TechCommunity #KeepLearning #Recursion #GrowthMindset #Motivation
To view or add a comment, sign in
-
-
🔥 Day 20 of My DSA Journey — LeetCode 3: Longest Substring Without Repeating Characters Today’s challenge focused on one of the most fundamental sliding window problems — finding the longest substring without repeating characters. It’s all about managing dynamic windows and smart indexing. 🧮 Brute Force Approach Generate all substrings and check if each has unique characters. Keep track of the longest valid substring. ❌ Time complexity: O(n³) (checking uniqueness for each substring). Too slow for large strings! ⚙️ Better Approach — Sliding Window + Hash Map We can solve it efficiently in O(n) using two pointers and a map. 🧠 Idea: Use left and right pointers to define a moving window. Store the last index of each character in a map. When a character repeats, move left to max(left, lastIndex + 1) to skip duplicates. Continuously update the length of the current substring. ⏱️ Complexity Time: O(n) — each character processed once Space: O(min(n, charset)) — depends on the number of unique characters ✨ Key Takeaway This problem perfectly demonstrates sliding window optimization — adjusting boundaries dynamically for real-time problem-solving. It teaches how maps can track state efficiently and avoid redundant checks. 🚀 #DSAJourney #Day20 #LeetCode3 #LongestSubstring #SlidingWindow #HashMap #Strings #CPlusPlus #CodingChallenge #ProblemSolving #InterviewPrep #DSA #100DaysOfCode #CodeEveryday #OptimizedApproach #BruteForceToOptimal #Algorithms #LearnDSA #DSAMastery #ProgrammerLife #TechLearning #CodingCommunity
To view or add a comment, sign in
-
-
💻 Day 34 of #100DaysOfLeetCode Today’s Challenge: 83. Remove Duplicates from Sorted List 🔹 Problem: Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well. Key Insight: Because the list is already sorted, duplicates will always be adjacent—this allows us to remove them in a single pass using pointer manipulation. 🔍 Approach: Traverse the list using a pointer. Compare current node with the next node. If values are equal → skip the next node by linking to the next of next. Otherwise → move forward. 🕒 Time Complexity: O(n) 📦 Space Complexity: O(1) ✨ Key Takeaway: This problem reinforces the importance of pointer manipulation and understanding how memory references work in linked lists. A simple check can eliminate duplicates efficiently without using extra space. Link:[https://lnkd.in/gsjVxHXM] #100DaysOfLeetCode #Day34 #LeetCode #ProblemSolving #DSA #Algorithms #LinkedList #CodingChallenge #CodeNewbie #InterviewPreparation #SoftwareEngineering #Programming #CodingCommunity #TechCareers #CareerGrowth #ArjunInfoSolution
To view or add a comment, sign in
-
-
Day 57 of My DSA Challenge Problem: Given an array and a window size k, find the count of distinct elements in every window of size k. Example: Input: arr = [1, 2, 1, 3, 4, 2, 3], k = 4 Output: [3, 4, 4, 3] Approach Used: Used a HashMap to efficiently keep track of the frequency of elements inside the current window. Initially processed the first k elements, then slid the window one step at a time: Added the next element (right end) Removed the leftmost element Stored the size of the HashMap (distinct count) after every window slide. Time Complexity: O(N) Space Complexity: O(K) Takeaway: The combination of HashMap + Sliding Window makes it possible to track frequencies dynamically, helping solve problems that once seemed to require nested loops — in just linear time #Day57 #DSAChallenge #SlidingWindow #HashMap #ProblemSolving #CodingInJava #DataStructures #Algorithms #100DaysOfCode #GeeksforGeeks #LeetCode #CodeOptimization #CodingJourney #LearnDSA
To view or add a comment, sign in
-
-
On Day 298 of my #300daysofcode challenge, I'm sharing my solution to LeetCode Problem 74, "Search a 2D Matrix." This problem is a classic demonstration of adapting the Binary Search algorithm to a 2D structure. My video provides a clear walkthrough of the key optimization: mapping $(row, col)$ indices to a single linear index to perform a fast, $O(\log(M \cdot N))$ search. This is a valuable skill for technical interviews and efficient matrix manipulation. #DataStructures #Algorithms #LeetCode #CodingInterview #Programming #BinarySearch #300daysofcode
To view or add a comment, sign in
-
I recently tackled LeetCode 2654 – Minimum Number of Operations to Make All Array Elements Equal to 1. Most solutions simulate every operation. The approach that worked for me came from stepping back and thinking mathematically: 1️⃣ If there’s already a 1 in the array, it can be spread to all other elements efficiently. 2️⃣ If no 1 exists, find the shortest subarray whose GCD is 1 – creating a 1 from that subarray is the minimal first step. 3️⃣ Once a 1 exists, the rest follows in a straightforward way. It’s a reminder that sometimes understanding the structure of a problem beats brute-force coding. And here’s a little validation: ✅ Runtime: 1ms, beats 100% of submissions ✅ Memory: 56.1MB, beats 100% of submissions For anyone doing coding challenges or preparing for interviews, focus on insights like these – they often save more time than writing extra lines of code. #ProblemSolving #Algorithms #CodingMindset #LeetCode #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Day 46 of 150 Days LeetCode Challenge #150DaysOfCode #LeetCode #CodingChallenge #DSA #HashMap #CPlusPlus #Programming #SoftwareEngineering #TechLearning #ProblemSolving #CodeDaily #LeetCode150DaysChallenge #Algorithm #DataStructures 🔹 Problem Statement:Contains Duplicate II Given an integer array nums and an integer k, check if there exist two distinct indices i and j in the array such that: nums[i] == nums[j] |i - j| <= k In simple words: “Does the array contain a duplicate within a distance of k?” 🔹 Example: Input: nums = [1,2,3,1], k = 3 Output: true Explanation: nums[0] and nums[3] are both 1, and the distance between them is 3 ≤ k. 🔹 Approach: Use a hash map to store each number with its most recent index. Iterate through the array: If the number already exists in the map, calculate the distance between the current index and the previous index. If this distance ≤ k, return true. Update the map with the current index. Return false if no such pair is found. Time Complexity: O(n) | Space Complexity: O(n) 🔹 Key Insights: ✅ Hash maps allow O(1) lookups for duplicates. ✅ Always update the index to track the most recent occurrence. ✅ Brute-force approaches take O(n²), but hash maps reduce it to O(n).
To view or add a comment, sign in
-
-
💡 Day 40 / 100 – Letter Combinations of a Phone Number (LeetCode #17) Today’s challenge was about generating all possible letter combinations from a string of digits on a phone keypad. This problem blends recursion and backtracking, testing both logic and creativity. Each digit maps to a set of letters (like on an old mobile keypad), and the goal is to explore every possible letter combination that could be formed. The key is to use recursion effectively — adding one letter at a time and exploring deeper until the combination is complete. 🔍 Key Learnings Recursion builds combinations step-by-step with clean logic. Backtracking helps explore multiple paths efficiently without redundant work. Using base conditions effectively keeps recursion under control and prevents infinite loops. 💭 Thought of the Day Sometimes, complex problems can be solved by thinking recursively — one small step at a time. This challenge reminded me that big results are just the outcome of many small, consistent actions — just like our 100 days of code journey. 🔗 Problem Link: https://lnkd.in/gUuS6Zp6 #100DaysOfCode #Day40 #LeetCode #Python #Recursion #Backtracking #ProblemSolving #CodingChallenge #Algorithms #DataStructures #CleanCode #PythonProgramming #LogicBuilding #KeepLearning #CodingJourney
To view or add a comment, sign in
-
-
🔹 DSA Daily | Check if Two Arrays are Equal At first glance, this problem looked simple — just compare two arrays, right? But then I realized, the order of elements doesn’t matter, only their frequency does. 💡 Problem Statement: Given two arrays, check if they contain the same elements with the same frequency, regardless of order. My Approach: I used unordered maps to count the frequency of each element in both arrays and then compared them. This small trick turned a potentially messy comparison into a clean and efficient solution. Time Complexity: O(n) — traversing both arrays once Space Complexity: O(n) — storing frequencies in hash maps Sometimes, a simple data structure like a hash map makes all the difference. It’s not just about solving the problem — it’s about writing elegant, efficient code. 🚀 #DSA #CPlusPlus #Coding #ProblemSolving #HashMap #Arrays #CodeEveryday #GeeksforGeeks #LeetCode #ProgrammingJourney #DataStructures #Algorithms #InterviewPrep #CodingCommunity #LogicBuilding #EfficientCode #LearnToCode #TechJourney
To view or add a comment, sign in
-
-
🚀 Day 31 of #100DaysOfCode — LeetCode + HackerRank Edition! Today’s challenge was all about tracking structure and resilience — decoding the longest valid parentheses substring in a given string. 🔗 Problem: longestValidParentheses(s) (LeetCode) 📌 Challenge: Given a string of '(' and ')', find the length of the longest well-formed (valid) parentheses substring. 🔍 Approach: → Used a stack to track indices of unmatched '(' characters → Introduced a base index to reset when encountering unmatched ')' → On each valid match, calculated the distance to the last unmatched index → Continuously updated the maximum valid length found so far 💡 What made it click: → Realized that tracking indices, not just characters, is key to measuring valid spans → Using stack[-1] after a pop gives the start of the current valid substring → Resetting with a base index ensures recovery after mismatches 📚 What I learned: ✅ Stack-based tracking is powerful for nested structures ✅ Index math reveals patterns that raw character matching misses ✅ Defensive coding (checking if stack is empty) prevents crashes and improves robustness ✅ Visual walkthroughs and guided hints make debugging intuitive and rewarding Have you tackled longestValidParentheses before? Did you go with dynamic programming, two-pass scanning, or stack-based logic like I did? Let’s swap strategies 💬 #Day30 #LeetCode #StackAlgorithms #ParenthesesMatching #Python #ProblemSolving #CleanCode #CodeEveryDay #LearnToCode #CodeNewbie #SoftwareEngineering #TechJourney #100DaysOfCode
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