Day 30/100 - LEETCODE Challenge ✅ Problem : Ransom Note Solved the Ransom Note problem using Java! I implemented an efficient approach using a frequency array to count the occurrences of each character in the magazine string and then reduced the count while checking the ransomNote string. If any character count becomes negative, it means the magazine does not have enough letters to construct the ransom note. This solution runs in O(n + m) time complexity with constant space (26 letters), making it highly optimized. ✅ Runtime: 1 ms (Beats 99.85%) ✅ Memory: 46.31 MB Great practice for understanding character frequency, arrays, and greedy checking techniques in string problems. #100DaysOfCode #java #Coding #SoftwareDeveloper
Ransom Note Solution in Java
More Relevant Posts
-
💻 LeetCode Practice – Day 15 Solved Valid Anagram (Problem 242) today. 📌 Problem: Given two strings s and t, return true if t is an anagram of s, otherwise return false. 🧠 Approach: • Check if both strings have the same length. • Use a frequency array to count characters. • Increment for s and decrement for t. • If all values become zero, the strings are anagrams. #LeetCode #Java #DSA #CodingPractice
To view or add a comment, sign in
-
-
🚀 Day 47/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 448. Find All Numbers Disappeared in an Array Used an in-place marking technique by treating indices as a hash map and marking visited numbers as negative to identify missing elements. ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) (excluding output list) Strengthening understanding of array manipulation and in-place hashing tricks. 💪 Consistency continues 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 88 - LeetCode Journey Solved LeetCode 24: Swap Nodes in Pairs in Java ✅ This problem is a great exercise in pointer manipulation in linked lists. Instead of changing values, I swapped the actual nodes by carefully adjusting the next pointers. Using a dummy node made the process much cleaner and helped handle edge cases smoothly. Step by step, I swapped pairs while moving forward in the list. Key takeaways: • Deep understanding of pointer manipulation • Importance of dummy node in linked list problems • Clean handling of edge cases • Iterative approach for swapping nodes ✅ All test cases passed ⚡ Efficient O(n) time and O(1) space Linked list problems like this really sharpen your fundamentals 🔥 #LeetCode #DSA #Java #LinkedList #Pointers #ProblemSolving #CodingJourney #InterviewPrep #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
Day 62 of #100DaysOfLeetCode 💻✅ Solved #219. Contains Duplicate II problem in Java. Approach: • Used two nested loops to compare elements within range k • For each element, checked next k elements • If any duplicate is found within distance k, returned true • If no such pair exists, returned false Key Learning: ✓ Practiced checking duplicates within a given range ✓ Strengthened understanding of array traversal with conditions ✓ Learned the importance of optimizing nested loop solutions Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 13/100 – LeetCode Challenge 🚀 Problem: #283 Move Zeroes Difficulty: Easy Language: Java Approach: Repeated Swapping / Zero Bubbling Time Complexity: O(n²) Space Complexity: O(1) 🔍 Key Insight: The goal is to move all **0s to the end** of the array while keeping the **relative order of non-zero elements unchanged**. Instead of creating a new array, the problem requires solving it **in-place**. 🧠 Solution Brief: First counted the total number of zeroes in the array. Then repeatedly traversed the array and whenever a **0** was found, swapped it with the next element. This process gradually pushes all zeroes toward the end of the array while preserving the order of the remaining elements. 📌 What I Learned: Even simple array problems require careful handling of constraints like **in-place modification** and **order preservation**. These problems also highlight the importance of thinking about **time complexity optimizations** for better performance. #LeetCode #Day13 #100DaysOfCode #Java #DSA #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 34/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 709. To Lower Case Used ASCII manipulation to convert uppercase letters to lowercase by adding 32, without using built-in functions. ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(n) Strengthening understanding of character encoding and string manipulation basics. 💪 Consistency continues 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 14/100 – LeetCode Challenge 🚀 Problem: #169 Majority Element Difficulty: Easy Language: Java Approach: Sorting + Middle Element Time Complexity: O(n log n) Space Complexity: O(1) 🔍 Key Insight: The majority element appears **more than ⌊n / 2⌋ times** in the array. If we **sort the array**, the majority element must occupy the **middle position** because it appears more than half of the time. Therefore, the element at index **n/2** will always be the majority element. 🧠 Solution Brief: First sorted the array using `Arrays.sort()`. Since the majority element appears more than half of the array length, it will always be positioned at the middle index. Finally returned `nums[nums.length / 2]` as the majority element. 📌 What I Learned: Understanding problem constraints can simplify the solution significantly. Sometimes a simple observation (like majority occupying the middle after sorting) can avoid more complex implementations. #LeetCode #Day14 #100DaysOfCode #Java #DSA #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 91 - LeetCode Journey Solved LeetCode 61: Rotate List in Java ✅ This one is a classic linked list problem where the trick is to avoid brute force rotations. Instead of rotating step by step, I converted the list into a circular linked list, calculated the effective rotations using k % length, and then broke the list at the right position. Simple idea, but powerful optimization. Key takeaways: • Converting list into circular form for easy rotation • Using modulo to reduce unnecessary operations • Finding new tail and head efficiently • Clean pointer manipulation ✅ All test cases passed ⚡ O(n) time and O(1) space Problems like this teach how to think smarter, not harder 💡 #LeetCode #DSA #Java #LinkedList #CodingJourney #ProblemSolving #InterviewPrep #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
Day 63 of #100DaysOfLeetCode 💻✅ Solved #2085. Count Common Words With One Occurrence problem in Java. Approach: • Iterated through each word in the first array • Avoided duplicate checks by ensuring each word is processed only once • Counted occurrences of the current word in both arrays • If the word appears exactly once in both arrays, incremented the result • Returned the final count Performance: ✓ Runtime: 88 ms (Beats 7.45% submissions) ✓ Memory: 46.06 MB (Beats 93.07% submissions) Key Learning: ✓ Practiced handling duplicates and frequency counting ✓ Improved understanding of string comparison in arrays ✓ Learned importance of optimizing nested loop solutions Learning one problem every single day 🚀 #Java #LeetCode #DSA #Strings #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 46/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 2315. Count Asterisks Used a boolean flag approach to track whether the current position is inside a pair of '|' and count only the valid '*' outside those sections. ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) Strengthening understanding of state-based string traversal and conditional counting. 💪 Consistency continues 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
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