DSA Day 20 – Frequency Counting with Strings Today I solved the “Ransom Note” problem on LeetCode. Problem: Check whether the ransomNote string can be constructed using letters from the magazine string, where each letter can be used only once. Approach Used: -> Counted frequency of characters in ransomNote -> Counted frequency of characters in magazine -> Compared required characters with available characters -> If any required count was greater than available count → false Time Complexity: -> O(n + m) Space Complexity: -> O(1) (Only lowercase English letters / limited character set) Key Learning: -> Frequency counting works not only for arrays, but also for strings -> HashMap helps compare required vs available resources efficiently -> Always check constraints, because they can reduce space complexity What I Realized: Many string problems are actually counting problems in disguise. The better you recognize patterns, the faster you solve problems. Thanks to Pulkit Aggarwal sir for guiding me in DSA and helping me understand problem-solving patterns. Consistency continues, one problem every day. #DSA #LeetCode #Java #ProblemSolving #CodingJourney #100DaysOfCode
Ransom Note Problem Solution with Frequency Counting
More Relevant Posts
-
🚀 DSA Every Day – Day 2 📍 Problem: Minimum Distance to Target Element 💡 Platform: LeetCode 🧠 Approach: Brute Force with Bidirectional Traversal 🔍 Problem Summary: Given an array, a target value, and a starting index, find the minimum distance between the start index and any index where the target exists. ⚙️ Approach Explained: Traverse forward (start → end) Traverse backward (start → beginning) For each occurrence of target: Compute distance → |start - i| Maintain the minimum distance 📈 Complexity Analysis: Time Complexity: O(n) Space Complexity: O(1) 🎯 Key Takeaways: Always think in terms of distance minimization problems Bidirectional traversal ensures complete coverage Can be optimized further using early stopping if needed Tell me your approach in comments ? Would love if people would like to join me in this habit for learning every day. 🔥 Progress: Day 2/ 60 #DSA #LeetCode #Java #CodingJourney #ProblemSolving #SoftwareEngineering #60DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 126/500 – LeetCode DSA Challenge Today I solved problems focused on strings and frequency counting. ✅ Ransom Note – Used frequency array to check if the note can be constructed from magazine characters. TC: O(n + m) | SC: O(1) ✅ Find Common Characters – Iteratively found common characters across all strings using string manipulation. TC: O(n × k) | SC: O(k) 💡 Key Learning: Frequency counting is a powerful technique for string problems, and careful string manipulation helps in handling character intersections. 👉 Day 126/500 #DSA #Java #500DaysChallenge #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
🚀 Day 21/100 Days of Code 📌 Problem Solved: Search Insert Position(Leetcode 35) Today I worked on a classic Binary Search problem that goes beyond just finding an element. The task was to return the index if the target exists, otherwise return the position where it should be inserted to maintain sorted order. 💡 Approach: Used Binary Search to reduce time complexity from O(n) to O(log n). By adjusting the search space using low and high, we can efficiently narrow down the correct position. 📈 What I learned: • Importance of handling edge cases • Writing optimal solutions instead of brute force • Deep understanding of how Binary Search works internally Every day is one step closer to mastering DSA 💪 #Day21 #100DaysOfCode #DSA #BinarySearch #Java #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🔥 Day 58 of DSA Journey Solved the classic 3Sum (LeetCode 15) problem today. 💡 Key Learnings: Sorting simplifies the problem structure Fix one element and apply the two-pointer approach Handling duplicates correctly is crucial to avoid redundant results ⏱️ Complexity: Time: O(n²) Space: O(1) (excluding output) 📊 Result: Runtime: 33 ms (Beats 73.75%) Strengthened understanding of two-pointer pattern This problem reinforced an important pattern: 👉 Reduce 3Sum → 2Sum using two pointers On to the next challenge 🚀 #DSA #LeetCode #CodingJourney #Java #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
📘 DSA Journey — Day 33 Today’s focus: Binary Search for next greater element. Problem solved: • Find Smallest Letter Greater Than Target (LeetCode 744) Concepts used: • Binary Search • Upper bound concept • Circular handling Key takeaway: The goal is to find the smallest character strictly greater than a given target in a sorted array. This is a classic upper bound problem: We use binary search to find the first element greater than the target. During search: • If letters[mid] > target, store it as a possible answer and move left • Else move right An important edge case: If no character is greater than the target, we return the first element (circular behavior). Continuing to strengthen binary search patterns and problem-solving consistency. #DSA #Java #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
🔥 DSA Challenge – Day 136/360 🚀 📌 Topic: Bit Manipulation 🧩 Problem: Number of 1 Bits (Hamming Weight) Problem Statement: Given an integer, return the number of set bits (1’s) present in its binary representation. 🔍 Example: Input: 6 Output: 2 Explanation: Binary of 6 → 110 → 2 set bits 💡 Optimized Approach (Brian Kernighan’s Algorithm): Instead of checking each bit one by one, we use a smart trick: n & (n - 1) removes the rightmost set bit in each iteration This reduces the number of operations to the number of set bits only ⚡ Time Complexity: O(k) (k = number of set bits) ⚡ Space Complexity: O(1) 🚀 Key Takeaway: Using bit manipulation can drastically optimize performance compared to brute force approaches. Always look for patterns in binary operations! #DSA #Coding #Java #BitManipulation #136DaysOfCode #LeetCode #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 DSA Journey Update: 7/75 Solved another problem today: Product of Array Except Self 💡 Key Idea: Used prefix (left) and suffix (right) products to build the answer without using division and in O(n) time. 🔍 Example: Input: [1,2,3,4] Output: [24,12,8,6] ⚡ Learning: Optimized approach using two passes Space optimization by reusing the same array Stronger understanding of prefix/suffix patterns Step by step progress… consistency matters more than speed 🔥 #DSA #Java #LeetCode #CodingJourney #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
Day 19 of #100DaysOfCode Solved “Base 7” problem today — a simple yet insightful exercise on number systems. 💡 Approach: Convert the integer into base 7 by repeatedly dividing by 7 and storing remainders. Handle negative numbers separately and reverse the result at the end. ⚡ Key Learning: Even easy problems strengthen fundamentals like loops, math logic, and edge case handling. Consistency > Complexity. #LeetCode #DSA #CodingJourney #Java #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 8 of #100DaysOfDSA Today’s problem: Longest Substring Without Repeating Characters 🧠 Problem Statement: Given a string, find the length of the longest substring without repeating characters. 💡 Approach: Sliding Window Technique Used two pointers (left & right) Maintained a HashSet to track characters Expanded window when unique Shrunk window when duplicate found ⚡ Key Learning: Efficient use of the sliding window helps reduce time complexity to O(n), which is crucial for optimizing string-based problems. 💻 Example: Input: "abcabcbb" Output: 3 ("abc") 🔥 This problem strengthened my understanding of: ✔️ Two-pointer technique ✔️ Hashing (Set/Map) ✔️ Optimizing brute force solutions Consistency is the key — small steps every day lead to big results 💪 #DSA #Java #CodingJourney #LeetCode #ProblemSolving #100DaysOfCode 🍁 Saidhanya Sree
To view or add a comment, sign in
-
-
🚀 LeetCode Daily Progress – Rotate Array Kicking off today’s DSA practice, I solved the “Rotate Array” problem on LeetCode. 🔍 Problem Overview: Given an integer array, rotate the array to the right by k steps, where k is non-negative. The rotation must be done in-place without using extra space. 💡 My Approach: Used the array reversal technique for optimal performance First reversed the initial part, then the remaining part, and finally the entire array Applied k = k % n to handle cases where k is greater than array size 📈 Key Takeaway: This problem reinforced my understanding of in-place array manipulation and how clever use of reversal algorithms can optimize both time and space complexity. Consistency is building confidence step by step 💯 #LeetCode #DSA #Java #Arrays #ProblemSolving #CodingJourney #SoftwareEngineering #Consistency #Learning
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