100 Days of Coding Challenge – Day 21 📌 Problem: Word Pattern 💻 Language: Java 🧠 Concept Used: HashMap + String Mapping 🔍 Platform: LeetCode A valid pattern means there must be a one-to-one mapping (bijection) between characters in the pattern and words in the string. In other words: • Each pattern character maps to exactly one unique word • Each word maps to only one pattern character Example: pattern = "abba" s = "dog cat cat dog" → ✅ true Approach: ✔ Split the string into words using split(" ") ✔ Use a HashMap to map pattern characters to words ✔ Ensure no two characters map to the same word ✔ Verify consistency during traversal Time Complexity: O(n) Space Complexity: O(n) 🔗 Problem Link: https://lnkd.in/grDzg_82 🔗 Code: https://lnkd.in/gA9CCyc5 #100DaysOfCode #Day21 #Java #DSA #LeetCode #HashMap #Strings #ProblemSolving #CodingJourney
Java HashMap Word Pattern Challenge
More Relevant Posts
-
100 Days of Coding Challenge – Day 26 📌 Problem: Remove Duplicates from Sorted Array II 💻 Language: Java 🧠 Concept Used: Two Pointer Technique + Counting 🔍 Platform: LeetCode Today’s challenge was to remove duplicates from a sorted array in-place, but this time allowing at most two occurrences of each element. Approach: ✔ Traverse the array and track occurrences using a counter ✔ Allow elements to appear at most twice ✔ Use a pointer k to place valid elements in the correct position ✔ Skip elements when they exceed the allowed count Time Complexity: O(n) Space Complexity: O(1) 🔗 Problem Link: https://lnkd.in/gm2_CHbz 🔗 Code: https://lnkd.in/gKxuTbsG #100DaysOfCode #Day26 #Java #DSA #LeetCode #TwoPointers #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
100 Days of Coding Challenge – Day 23 📌 Problem: Longest Consecutive Sequence 💻 Language: Java 🧠 Concept Used: Sorting + Sequence Counting 🔍 Platform: LeetCode Today’s challenge was to find the length of the longest sequence of consecutive numbers in an unsorted array. The numbers do not need to be adjacent in the original array, but they must form a continuous sequence like 1,2,3,4. Example: Input: [100, 4, 200, 1, 3, 2] Output: 4 → Longest sequence: [1,2,3,4] Approach: ✔ First sort the array ✔ Traverse the array and check if the next number is consecutive ✔ Skip duplicates ✔ Track the longest streak using a counter Time Complexity: O(n log n) (due to sorting) Space Complexity: O(1) 🔗 Problem Link: https://lnkd.in/gguN6KnH 🔗 Code: https://lnkd.in/gyVFpsbg #100DaysOfCode #Day23 #Java #DSA #LeetCode #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
100 Days of Coding Challenge – Day 30 📌 Problem: Find the Index of the First Occurrence in a String 💻 Language: Java 🧠 Concept Used: String Matching (Brute Force) 🔍 Platform: LeetCode Today’s challenge was to find the first occurrence of a substring (needle) in a given string (haystack). If not found, return -1. Example: Input: "sadbutsad", "sad" Output: 0 Approach: ✔ Traverse the string from index 0 to n - m ✔ Extract substring of length m at each position ✔ Compare it with the target string ✔ Return index immediately when match is found ✔ If no match → return -1 Time Complexity: O(n × m) Space Complexity: O(1) 🔗 Problem Link: https://lnkd.in/g2ktYFFS 🔗 Code: https://lnkd.in/gynFixSQ #100DaysOfCode #Day30 #Java #DSA #LeetCode #Strings #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
100 Days of Coding Challenge – Day 28 📌 Problem: Find First and Last Position of Element in Sorted Array 💻 Language: Java 🧠 Concept Used: Binary Search (Modified) 🔍 Platform: LeetCode Today’s challenge was to find the starting and ending positions of a target value in a sorted array. If the target is not found → return [-1, -1]. Approach: ✔ Use Binary Search since the array is sorted ✔ Perform two searches: • One to find the first occurrence • One to find the last occurrence ✔ Narrow the search space based on comparisons ✔ Combine both results into the final answer Time Complexity: O(log n) Space Complexity: O(1) 🔗 Problem Link: https://lnkd.in/gK5EM63Z 🔗 Code: https://lnkd.in/gMwMsF7R #100DaysOfCode #Day28 #Java #DSA #LeetCode #BinarySearch #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
100 Days of Coding Challenge – Day 29 📌 Problem: Isomorphic Strings 💻 Language: Java 🧠 Concept Used: HashMap + Bidirectional Mapping 🔍 Platform: LeetCode Two strings are isomorphic if characters in one string can be replaced to get the other string with a one-to-one mapping, while preserving order. Example: s = "egg", t = "add" → ✅ true Approach: ✔ Traverse both strings simultaneously ✔ Use two HashMaps: • One for mapping s → t • One for mapping t → s ✔ Ensure consistency in both directions ✔ If any mismatch occurs → return false Time Complexity: O(n) Space Complexity: O(n) 🔗 Problem Link: https://lnkd.in/gHJ3Vn2a 🔗 Code: https://lnkd.in/gWrRUiN4 #100DaysOfCode #Day29 #Java #DSA #LeetCode #HashMap #Strings #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 93 - LeetCode Journey Solved LeetCode 9: Palindrome Number in Java ✅ At first glance, it feels like a string problem… but the real challenge is solving it without converting to string. Instead of reversing the whole number, I reversed only half of it and compared both parts. This avoids overflow and keeps it efficient. Smart approach > brute force 💡 Key takeaways: • Handling edge cases (negative numbers, trailing zeroes) • Reversing only half of the number • Avoiding extra space (no string conversion) • Writing optimized mathematical logic ✅ All test cases passed ⚡ O(log n) time and O(1) space Sometimes the best solutions are the simplest ones, just a different way of thinking 🔥 #LeetCode #DSA #Java #Math #ProblemSolving #CodingJourney #InterviewPrep #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
100 Days of Coding Challenge – Day 27 📌 Problem: Maximum Average Subarray I 💻 Language: Java 🧠 Concept Used: Sliding Window Technique 🔍 Platform: LeetCode Today’s challenge was to find a contiguous subarray of length k that has the maximum average value. Example: Input: [1,12,-5,-6,50,3], k = 4 Output: 12.75 Approach: ✔ Calculate the sum of the first window of size k ✔ Slide the window by removing the left element and adding the next element ✔ Keep track of the maximum sum ✔ Divide by k to get the maximum average Time Complexity: O(n) Space Complexity: O(1) 🔗 Problem Link: https://lnkd.in/ghU4zrpt 🔗 Code: https://lnkd.in/g7qXeHx6 #100DaysOfCode #Day27 #Java #DSA #LeetCode #SlidingWindow #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 18 of my Java DSA Journey Today I solved " Find the Index of the First Occurence in a String "— LeetCode Problem #28. 🔹 Problem Given two strings haystack and needle, return the index of the first occurrence of "needle" in "haystack". If the substring does not exist, return -1. 🔹 Approach Used: Substring Search (Brute Force) Idea • Check every possible starting index in the main string. • Compare characters of needle with haystack one by one. • If all characters match, return that starting index. 📊 Complexity • Time Complexity: O(n × m) • Space Complexity: O(1) 💡 Key Learning Understanding the brute-force approach helps build the foundation for more advanced string matching algorithms like KMP. 🔗 GitHub Solution: https://lnkd.in/gW8atfqw Consistent daily practice is helping me improve my problem-solving and algorithmic thinking step by step. #Java #DSA #LeetCode #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 49 of #100DaysOfLeetCode 💻✅ Solved #387. First Unique Character in a String problem in Java. Approach: • Created an array of size 26 to store the frequency of each character • Traversed the string and counted how many times each character appears • Traversed the string again to find first character with frequency equal to 1 • Returned the index of that character • If no unique character is found, returned -1 Performance: ✓ Runtime: 6 ms (Beats 84.58% submissions) ✓ Memory: 47.16 MB (Beats 36.29% submissions) Key Learning: ✓ Practiced using frequency arrays for string problems ✓ Learned how counting characters helps find unique elements efficiently ✓ Strengthened understanding of string traversal and indexing Learning one problem every single day 🚀 #Java #LeetCode #DSA #Strings #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 65 of #100DaysOfLeetCode 💻✅ Solved “Majority Frequency Group” problem in Java. Approach: • Created a frequency array of size 26 for all characters • Counted occurrences of each character in the string • For each unique frequency, counted how many characters share that frequency • Selected the frequency with the highest group size • In case of tie, chose the higher frequency • Built the result string with characters having the selected frequency Performance: ✓ Runtime: 5 ms (Beats 57.84% submissions) ✓ Memory: 44.51 MB (Beats 72.88% submissions) Key Learning: ✓ Practiced frequency grouping techniques ✓ Learned how to handle tie-breaking conditions ✓ Strengthened logic building with nested loops and conditions Learning one problem every single day 🚀 #Java #LeetCode #DSA #Strings #Hashing #ProblemSolving #CodingJourney #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