🚀 Another good one of the Day 43 of #100DaysOfCode 💻🔥 🔹 Problem: Find All Anagrams in a String 🎯 You’re given two strings s and p. The goal is to find all starting indices of p’s anagrams in s. 💡 My Intuition: Think of it like sliding a window over s while keeping track of character frequencies. If the frequency of characters inside the current window matches that of p, we’ve found an anagram. We maintain two arrays of size 26 (for each lowercase letter): arr → frequency of chars in p arr2 → frequency of chars in current window of s We keep sliding the window of size p.length() and compare both arrays at each step. 🧠 Key takeaway: Sliding window + frequency matching = powerful combo for string problems! It improves your intuition for optimizing brute-force solutions efficiently. 💪 #100DaysOfCode #LeetCode #DSA #Java #CodingJourney #ProblemSolving #KeepLearning
How to find all anagrams in a string using Java
More Relevant Posts
-
🎯 LeetCode 2390 – Removing Stars From a String Today I solved another interesting Stack / String Manipulation problem! 💡 Problem Summary: You’re given a string s containing lowercase letters and *. Each * means you must remove the closest non-star character to its left along with the star itself. Your task is to return the final string after all operations. 🧠 Approach: I used a StringBuilder as a stack to simulate the process. Traverse through the string. If the current character is not *, append it. If it’s *, remove the last added character. Finally, return the resulting string. ⏱️ Time Complexity: O(n) 💾 Space Complexity: O(n) #LeetCode #Java #DSA #Stack #CodingJourney #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
✨ Day 54 of 100: Reverse Nodes in k-Group ✨ Today’s challenge was LeetCode 25 – Reverse Nodes in k-Group 🔁 🧩 Problem: Given a linked list, reverse the nodes of the list k at a time and return its modified list. If the number of nodes is not a multiple of k, the remaining nodes should remain as-is. 💡 Key Takeaways: 🔹 Strengthened understanding of linked list manipulation and pointer handling. 🔹 Practiced breaking the list into segments of size k and reversing each group independently. 🔹 Learned how to manage head and tail connections between reversed and remaining parts. 🔹 Reinforced problem-solving using dummy nodes to simplify list operations. 🧠 Approach: 1️⃣ Count the total nodes to know how many full groups of k exist. 2️⃣ For each group, reverse k nodes iteratively. 3️⃣ Connect the reversed group to the next segment. 🧭 Insight: This problem beautifully illustrates how iteration with precise pointer movement can replace recursion while still achieving elegant reversals in linked lists. #100DaysOfCode #Day53 #LeetCode #Java #LinkedList #CodingJourney #DSA #ProblemSolving
To view or add a comment, sign in
-
-
Today’s problem: Merge Two Sorted Lists 🔗 Problem: Given two sorted linked lists, merge them into one sorted list and return it. Example: Input: list1 = [1,2,4], list2 = [1,3,4] Output: [1,1,2,3,4,4] Approach I used: ✅ Create a dummy node to simplify pointer operations. ✅ Use a pointer (tail) to build the merged list by comparing the heads of both lists. ✅ Append the smaller node each time and move forward. ✅ When one list ends, attach the remaining nodes of the other. A clean iterative solution that keeps the space usage minimal (O(1) extra space). ⚡
To view or add a comment, sign in
-
-
🚀 #SridharSolves100 – Day 97 | Smallest Number With All Set Bits 💡 Today’s challenge was all about bit manipulation brilliance 🧠💻 🧩 Problem: Given a number n, find the smallest number x ≥ n such that the binary representation of x contains only set bits (1s). Approach: 1. Find the highest bit length of n. 2. Generate a number of the same bit-length with all bits set → (1 << bits) - 1. 3. If this number < n, increase bit length by 1 and repeat. 4. Return the resulting all-1s number. 5. Bitwise shifts make this constant-time for small n. ⏱️ Complexity: Time – O(1) | Space – O(1) 💡 Real-world analogy: 1. Imagine lighting a sequence of bulbs 🔆— we keep extending the row until all bulbs stay ON continuously from the start. 🔗 My Solution: https://shorturl.at/jyMqs #100DaysOfCode #SridharSolves100 #BitManipulation #Java #LeetCode #ProblemSolving
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
-
-
💡 Day 34/100 ✅ Remove Zeros in Decimal Representation Today’s challenge was about removing all the zeros from a given number’s decimal form. For example, 1020030 → 123. It might look simple, but it reinforced the importance of handling edge cases like n = 0 or n = 1000, which can lead to empty strings or parsing errors. 🧠 Key Features: Practiced both String-based and Math-based approaches. Explored the difference between using int and long for large numbers. Strengthened understanding of number-to-string conversions and parsing. ⚙️ Time Complexity: O(d) (where d = number of digits) 💾 Space Complexity: O(d) #Day33Of100 #DSA #Java #ProblemSolving #CodingJourney #100DaysOfCode #LearnEveryday #LogicBuilding
To view or add a comment, sign in
-
-
🚀 Day 118 of 120 – #DSAwithJava Challenge Hey LinkedIn fam! 👋 Today’s problem was all about Linked Lists and HashSets — a combination that makes node deletions efficient and elegant ⚡ ✅ Problem: Delete Nodes From Linked List Present in Array (LeetCode #3217 – Medium) 🎯 Objective: Given an array nums and the head of a linked list, remove all nodes whose values exist in nums. 🧠 Key Insight: Store all elements of nums in a HashSet for O(1) lookups. Use a dummy node before the head to handle edge deletions easily. Traverse the list, and if a node’s value exists in the set, skip it by adjusting pointers. The result is a clean linked list containing only valid nodes. 💡 Example: Input → nums = [1,2,3], head = [1,2,3,4,5] Output → [4,5] 🕒 Time Complexity: O(n + m) 📦 Space Complexity: O(m) 🔥 Takeaway: When dealing with linked lists, HashSets simplify membership checks, and dummy nodes simplify pointer logic. A small design tweak can lead to clean and optimal solutions! 💪 #120DaysOfCode #DSAwithJava #LeetCode #Java #LinkedList #HashSet #ProblemSolving #CodingChallenge #TechJourney #Consistency #LearnByDoing
To view or add a comment, sign in
-
-
🚀Day 38/100 - Problem of the day :- Ones and Zeros. 🎯 Goal Solve the “Ones and Zeroes” problem using Dynamic Programming by selecting the maximum number of binary strings within the constraints of m zeroes and n ones. 💡 Core Idea Convert each string into its count of zeroes and ones, then use a 2D DP array where dp[i][j] tells the maximum number of strings that can be formed with i zeroes and j ones. Iterate in reverse to avoid overwriting states, updating DP for each string. 📌 Key Takeaway This problem shows how DP shines when choices are constrained by multiple resource limits. Turning strings into (zero, one) pairs and applying knapsack logic simplifies the solution beautifully. 📄 Space Complexity O(m × n) ⏱️Time Complexity O(k × m × n) where k is the number of strings #100DaysChallenge #Java #DataStructure #Day38 #Leetcode #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Just Solved LeetCode #110 — Balanced Binary Tree 📘 Problem: Given the root of a binary tree, determine if it is height-balanced — that is, for every node, the height difference between the left and right subtree should not exceed 1. Example: Input → [3,9,20,null,null,15,7] Output → true 🧠 My Approach: I used a bottom-up recursive approach to check balance efficiently. 1️⃣ For each node, I calculated the height of its left and right subtrees. 2️⃣ If any subtree was unbalanced, I returned -1 immediately to stop further checks. 3️⃣ If the height difference between left and right subtrees was greater than 1, I marked the tree as unbalanced. 4️⃣ Otherwise, I returned the height of the current node as 1 + max(left, right). This approach ensures every node is visited only once — making it O(n) in time complexity. 💡 What I Learned: ✅ The difference between top-down and bottom-up recursion in tree problems ✅ How to optimize recursion by early termination when imbalance is detected ✅ Strengthened my understanding of recursive depth and height calculation in binary trees #LeetCode #Java #DSA #BinaryTree #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 43 of #100DaysOfLeetCode Today's problem: LeetCode #160 – Intersection of Two Linked Lists 💡 Concept: Find the node where two singly linked lists intersect. Used the Two Pointer Approach — a smart and efficient way to solve this without using extra memory. 🧠 Logic: Move both pointers through the lists. When one pointer reaches the end, switch it to the other list’s head. They’ll either meet at the intersection node or end up as null together. ✅ Complexity: Time – O(n + m) Space – O(1) 💬 Takeaway: Sometimes, the best solutions come from balancing the path — literally! Understanding how pointers sync up teaches a lot about memory references and linked list behavior. #LeetCode #CodingChallenge #Java #DataStructures #TwoPointerTechnique #ProblemSolving #LinkedLists
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