📌 Day 14/100 - Group Anagrams (LeetCode 49) 🔹 Problem: Given an array of strings, group the anagrams together. An anagram is a word formed by rearranging the letters of another — like “eat”, “tea”, and “ate”. 🔹 Approach: Traverse through each word in the array. Sort its characters alphabetically to form a key. Use a HashMap to group words with the same key. Return all grouped lists as the final result. 🔹 Key Learning: ✅ Sorting helps identify similar string patterns. ✅ HashMaps make grouping efficient and clean. ✅ Small logical steps lead to elegant solutions. Consistent effort turns complexity into clarity 💪 #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney #LearningEveryday
Grouping Anagrams with HashMap and Sorting in Java
More Relevant Posts
-
📌 Day 13/100 - Valid Anagram (LeetCode 242) 🔹 Problem: Given two strings s and t, determine whether t is an anagram of s. An anagram is formed by rearranging the letters of one word to create another word — meaning both strings must have the same characters with the same frequency. 🔹 Approach: First, check if both strings are of equal length — if not, they can’t be anagrams. Convert both strings into character arrays. Sort both arrays and compare them using Arrays.equals(). If both sorted arrays are identical, the strings are anagrams. 🔹 Key Learning: Sorting can simplify comparison-based string problems. Always check base conditions (like length) to avoid unnecessary computation. This approach has a time complexity of O(n log n) due to sorting, which is efficient enough for this problem. Every solved challenge is another letter added to the dictionary of progress! 🚀 #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
📌 Day 16/100 - Reverse String (LeetCode 344) 🔹 Problem: Reverse a given string in-place — meaning you must modify the original array of characters without using extra space. 🔹 Approach: Used the two-pointer technique — one starting at the beginning and one at the end of the array. Swap characters at both pointers, then move them closer until they meet. Efficient, clean, and runs in linear time without additional memory allocation. 🔹 Key Learnings: In-place algorithms optimize space complexity significantly. The two-pointer pattern is a versatile tool for many array and string problems. Understanding mutable vs immutable structures in Java is crucial for memory efficiency. Sometimes, the simplest logic beats the most complex one. 🧠 “True efficiency lies in simplicity, not complexity.” #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney #TwoPointers
To view or add a comment, sign in
-
-
#Day_28 Today’s problem was quite an interesting one — “Reach a Target Number” using minimal moves. 💡 Problem Summary: Starting from 0, on each move i, you can go either left or right by i steps. The goal is to find the minimum number of moves required to reach a given target. At first glance, it looked like a simple math problem, but the trick was to notice the parity condition — once the cumulative sum goes beyond the target, the difference (sum - target) must be even to allow flipping directions and still land exactly on target. Here’s the optimized logic I implemented in Java Key Takeaway: Sometimes, problems that look complex are just about observing patterns in numbers rather than brute force. A touch of math can simplify the entire logic! #100DaysOfCode #LeetCode #CodingChallenge #Java #ProblemSolving #DSA #LearnEveryday #CodingJourney
To view or add a comment, sign in
-
-
📌 Day 11/100 – Longest Common Prefix (LeetCode 14) 🔹 Problem: Given an array of strings, find the longest common prefix shared among them. If no common prefix exists, return an empty string. 🔹 Approach: I first sorted the array of strings in alphabetical order. The idea is that only the first and last strings in the sorted order will differ the most — so the common prefix between them is also the prefix for the entire array. I then compared characters one by one between these two strings to extract the prefix efficiently. 🔹 Key Learning: Sorting simplifies comparison by aligning similar prefixes together. Smart observation can reduce unnecessary iterations. Sometimes, the most optimal logic lies in choosing the right perspective. Step by step, improving problem-solving clarity and confidence 💪 #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney #LearnByDoing #CodingChallenge
To view or add a comment, sign in
-
-
📌 Day 2/100 – Remove Element (LeetCode 27) 🔹 Problem: Given an integer array nums and a value val, remove all instances of that value in-place and return the new length of the array. The order of elements can be changed. 🔹 Approach: Used the two-pointer technique to efficiently modify the array in-place. One pointer iterates through the array, while the other tracks the position to overwrite non-val elements. Returned the position of the second pointer as the new length. 🔹 Key Learning: Strengthened understanding of in-place array manipulation. Improved logic building for pointer movement and conditional overwriting. Learned how to minimize extra space usage while maintaining readability and clarity. Another small yet powerful step toward mastering array-based problems! 💻 🔥 #100DaysOfCode #LeetCode #Java #ProblemSolving #TwoPointers #DSA #CodingJourney
To view or add a comment, sign in
-
-
💡 LeetCode #15 — 3Sum Today I solved LeetCode Problem 15: 3Sum 🔍 Problem Summary: Given an integer array nums, return all unique triplets (a, b, c) such that: a + b + c = 0 The solution must not contain duplicate triplets. Key Idea: Use sorting + two pointers to reduce the time from O(n³) to O(n²). Steps: Sort the array. Fix one number (nums[f]) in each iteration. Use two pointers (i and j) to find pairs whose sum equals -nums[f]. Skip duplicates for both the fixed index and the pointer values. This efficiently finds all unique triplets. #LeetCode #Java #DSA #TwoPointers #ProblemSolving #CodingChallenge #Algorithms
To view or add a comment, sign in
-
-
💻 Strengthening Problem-Solving Skills with LeetCode (Java) Recently explored a few interesting problems that focused on string manipulation, array traversal, and text formatting — each reinforcing clarity and precision in algorithmic thinking: 🔹 Text Justification Implemented a custom text alignment algorithm that evenly distributes spaces between words to fit a given line width. Approach: Greedy + StringBuilder Time Complexity: O(n) 🔹 Two Sum II – Input Array Is Sorted Solved using a two-pointer technique to efficiently find pairs that add up to a target value in a sorted array. Approach: Two Pointers Time Complexity: O(n) 🔹 Is Subsequence Checked whether one string is a subsequence of another using linear traversal and pointer comparison. Approach: Two Pointers Time Complexity: O(n) 🔹 Valid Palindrome Validated alphanumeric palindromes by filtering characters and comparing from both ends. Approach: String cleaning + two-pointer comparison Time Complexity: O(n) These problems helped sharpen my logic-building process and improved my confidence in designing efficient, readable solutions. #LeetCode #Java #ProblemSolving #DSA #Algorithms #Coding #SoftwareEngineering
To view or add a comment, sign in
-
✅Day 50 : Leetcode 1283 - Find the Smallest Divisor Given a Threshold #60DayOfLeetcodeChallenge 🧩 Problem Statement: Given an array of integers nums and an integer threshold, find the smallest positive integer divisor such that the sum of each element divided by the divisor (rounded up to the nearest integer) is less than or equal to the threshold. 💡 My Approach: Binary Search on Divisor Range: The smallest possible divisor is 1. The largest possible divisor is the maximum element in nums. Check Function: For a given divisor, calculate the sum of ceil(nums[i] / divisor) for all elements. If the total sum ≤ threshold → we can try smaller divisors. Otherwise, increase the divisor. Repeat until optimal divisor is found. ⏱️ Time Complexity: O(n * log(max(nums))) Each binary search iteration takes O(n) to compute the sum. #Algorithms #BinarySearch #LeetCode #Java #ProblemSolving #DSA #100DaysOfCode #CodeNewbie
To view or add a comment, sign in
-
-
Winter may be coming ❄️, but the code still runs fast ⚔️ Cracked one of the toughest LeetCode Hard problems – Median of Two Sorted Arrays 🔥 Hit 100% runtime efficiency (1 ms) with clean and optimized binary search logic 🧠 This one tested everything — edge cases, math logic, and patience 😅 But as they say… “You win or you debug again.” 🐉 #LeetCode #DSA #CodingJourney #BinarySearch #Java #ProblemSolving #WinterIsComing #GameOfCodes
To view or add a comment, sign in
-
-
🚀 Day 25 of 100 Days of LeetCode 📘 Problem: Remove Nth Node from End of List 💻 Language: Java ✅ Status: Accepted — Runtime: 0 ms ⚡ (Beats 100%) Today’s challenge was about working with Linked Lists, one of the most fundamental yet tricky data structures in DSA. The problem required removing the Nth node from the end — which tested how well I could use two-pointer techniques efficiently. ✨ Key Learnings: The two-pointer approach simplifies traversal logic beautifully 🎯 Dummy nodes are game-changers for clean code and edge case handling Linked Lists demand visualization — drawing it out helps a lot! Every accepted solution sharpens my ability to reason through edge cases and optimize thought flow 🔄 #Day25 #100DaysOfCode #LeetCode #Java #LinkedList #ProblemSolving #CodingJourney #DSA #SoftwareDevelopment #CodeEveryday #KeepLearning
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
Keep it up brother AJAY KUMAR