Day 23 of problem solving– Valid Anagram | DSA in Java Today I solved the “Valid Anagram” problem. Problem Statement: Given two strings s and t, return true if t is an anagram of s, and false otherwise. 🔹 An anagram means both strings contain the same characters with the same frequency. Approach I Used: Instead of sorting both strings (which takes O(n log n)), I used a frequency array technique for better performance. Logic: If lengths are different → return false. Create an integer array of size 26. Increase count for characters in first string. Decrease count for characters in second string. If all values are zero → it’s a valid anagram. ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) (Fixed size array) 📌 Key Learning: Using a frequency counter is more efficient than sorting when dealing with character-based problems. Consistency > Motivation Slowly building problem-solving strength every day. #DSA #Java #100DaysOfCode #CodingJourney #SoftwareEngineer
Valid Anagram Problem Solution in Java
More Relevant Posts
-
💻 Practicing Binary to Decimal Conversion using Java Today I worked on converting a binary number into its decimal equivalent using logic and iteration. 🔍 Key Learnings: Understanding how binary digits map to powers of 2 Strengthening loop and mathematical logic Improving problem-solving skills step by step Instead of just memorizing, I focused on understanding the logic deeply and practicing with different inputs. 📌 Example: Binary: 1010 → Decimal: 10 Consistency + Practice = Progress 🚀 #Java #DSA #CodingJourney #Programming #100DaysOfCode #LearnToCode #ProblemSolving #DeveloperJourney #CodingPractice #TechSkills
To view or add a comment, sign in
-
-
🚀 Inverted Star Pattern Using Nested Loops in Java After building a normal star pattern, today I implemented the inverted star pattern using the same nested loop logic — but with a different approach in controlling the loop conditions. Pattern Output: * * * * * * * * * * 💡 What this taught me: ✔ How changing loop conditions changes the entire structure ✔ Better understanding of outer & inner loop coordination ✔ Stronger grip on pattern-based logic building ✔ Thinking in reverse logic (important for DSA) Small pattern problems like this may look simple, but they seriously improve logical thinking and control over loops. Step by step, building strong fundamentals in Java. 💻🔥 #Java #DSA #CodingPractice #ProgrammingJourney #LearningInPublic #StudentDeveloper
To view or add a comment, sign in
-
-
🚀 Day 23 of My DSA Journey Today I solved “Check if Binary String Has at Most One Segment of Ones” on LeetCode using Java. 🧠 Understanding the Problem The task was to check whether a binary string contains at most one contiguous segment of 1s. A contiguous segment means all the 1s appear together without being separated by 0s. Example: 111000 → ✅ Only one segment of 1s 110011 → ❌ Two separate segments of 1s 💡 Key Observation If a string contains more than one segment of 1s, there must be a pattern where a 0 appears between two groups of 1s, which creates the substring "01" followed later by another 1. So the idea becomes very simple: If the string contains "01" → there are multiple segments of 1s → return false If "01" does not appear → only one segment of 1s exists → return true ⚡ Approach Instead of manually counting segments, I used a string pattern check to detect "01". 📊 Complexity ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) 📌 Key Learning Sometimes the best solution comes from recognizing patterns in the data rather than building complex logic. Simplifying the observation can lead to very clean and efficient solutions. On to Day 24 of the journey 🚀 #DSA #Java #LeetCode #CodingJourney #ProblemSolving #InterviewPreparation
To view or add a comment, sign in
-
-
🚀 DSA in Java – Day 84 Today’s problem was all about matrix rotation and pattern matching 🧠💡 🔍 Problem: Determine whether a given matrix can be rotated (0°, 90°, 180°, 270°) to match a target matrix. 💡 Key Learning: Matrix rotation is a pattern-based transformation problem Instead of manually checking all possibilities, we can: ✔ Rotate the matrix step by step ✔ Compare after each rotation Clean logic + iteration = efficient solution 🛠 Approach: Rotate matrix 4 times (0°, 90°, 180°, 270°) After each rotation, check if it matches the target If match found → return true, else false 📈 What I improved today: Matrix manipulation skills Thinking in rotations & transformations Writing clean and reusable functions 🔥 Consistency is the key! Day 84 done, moving closer to mastery. #DSA #Java #100DaysOfCode #CodingJourney #LeetCode #ProblemSolving #WomenInTech
To view or add a comment, sign in
-
-
🚀 DSA Learning Journey | Day 2 | Java Solved “Next Permutation.” 💡 Key Idea: Find the first decreasing element from the right, swap it with the next greater element, then reverse the remaining suffix to get the next lexicographical permutation. ⚙ Implementation • Language: Java • Time Complexity: O(n) • Space Complexity: O(1) 📚 Learning how permutation logic works and how reversing the suffix ensures the next smallest arrangement. #Java #DSA #LeetCode #ProblemSolving #JavaDeveloper #Algorithms
To view or add a comment, sign in
-
-
💡 3 Bit Manipulation Tricks Every Developer Should Know While revising Bit Manipulation, I came across some simple but powerful tricks that make certain problems much easier. 🔹1. Check if a number is a power of 2 A number is a power of 2 if it has only one set bit. Example trick: `n & (n - 1) == 0` This removes the rightmost set bit. If the result becomes 0, the number is a power of 2. Example: `8 (1000) & 7 (0111) = 0000` --- 🔹2. Find the only unique number in an array If every element appears twice except one, XOR can help. Key idea: `a ^ a = 0` `a ^ 0 = a` Example: `[2, 3, 2, 4, 3]` `` 2 ^ 3 ^ 2 ^ 4 ^ 3 = (2 ^ 2) ^ (3 ^ 3) ^ 4 = 4 🔹3. Remove the last set bit Very useful trick: `n & (n - 1)` Example: `12 = 1100` `11 = 1011` 1100 &1011 ---- 1000 This removes the rightmost set bit --- Bit manipulation looked confusing initially, but these small tricks make many problems much simpler. Currently revising DSA + Java fundamentals and exploring Low Level Design alongside. More learnings coming soon 🚀 #DSA #BitManipulation #CodingInterview #SoftwareEngineering
To view or add a comment, sign in
-
-
✨DAY-13: 🔁 Polymorphism in Java – Same Method, Different Behavior! This image perfectly explains one of the most powerful concepts in OOP — Polymorphism 👇 🐾 Base Class: Animal() 🐶 Derived Classes: Dog() and Cat() The programmer simply says: 👉 “Objects, do your thing!” 😎 And what happens? 🐕 Dog responds: “Woof! Woof!” 🐈 Cat responds: “Meow!” Same method call. Different outputs. That’s the beauty of runtime polymorphism (method overriding) in Java. 💡 Technical Insight: When we use a parent class reference like: Animal obj = new Dog(); obj.sound(); Java decides at runtime which method to execute. This is called Dynamic Method Dispatch. 📌 Why Polymorphism Matters: Increases flexibility Improves scalability Promotes clean and maintainable code Follows the “program to interface, not implementation” principle In simple terms: You give the same command… But each object responds in its own way. That’s real-world programming power. 💻🔥 #Java #OOP #Polymorphism #Programming #SoftwareDevelopment #CodingLife #TechConcepts
To view or add a comment, sign in
-
-
🚀 LeetCode Day 18 – Complement of Base 10 Integer Today I solved LeetCode Problem 1009: Complement of Base 10 Integer using Java. 🧠 Problem: Given a non-negative integer n, return the complement of its binary representation. The complement means flipping all bits in the binary form of the number. 📌 Example: Input: n = 5 Binary of 5 → 101 Complement → 010 Output → 2 💡 Approach: • Create a bitmask with all bits set to 1 up to the highest bit of n. • Use the XOR (^) operator with the mask to flip the bits. 💻 Java Code: class Solution { public int bitwiseComplement(int n) { if (n == 0) return 1; int mask = 0, temp = n; while (temp > 0) { mask = (mask << 1) | 1; temp >>= 1; } return n ^ mask; } } ⏱️ Time Complexity: O(log n) 📦 Space Complexity: O(1) 📚 Practicing Data Structures & Algorithms daily to improve problem-solving skills. #LeetCode #Java #DSA #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 57 of #100DaysOfLeetCode 💻✅ Solved #506. Relative Ranks problem in Java. Approach: • Iterated through each player's score • Compared it with all other scores to determine its rank • Increased rank whenever a higher score was found • Assigned medals for top 3 ranks: Gold, Silver, Bronze • Converted remaining ranks to string and stored in result array Performance: ✓ Runtime: 124 ms (Beats 5.06% submissions) ✓ Memory: 46.76 MB (Beats 99.84% submissions) Key Learning: ✓ Understood ranking logic using comparison ✓ Practiced nested loop approach for problem solving ✓ Learned the importance of optimizing time complexity Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #Sorting #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 97 of My 100 Days LeetCode Challenge | Java Today’s problem was a solid exercise in matrix processing and prefix sum optimization. The goal was to count the number of submatrices whose sum is less than or equal to a given value (k). A brute-force approach would be too slow, so the key was to use 2D prefix sums to efficiently compute submatrix sums. By converting the matrix into a prefix sum matrix, we can calculate the sum of any submatrix in constant time, making the overall solution much more efficient. ✅ Problem Solved: Count Submatrices With Sum ≤ K ✔️ All test cases passed (859/859) ⏱️ Runtime: 7 ms 🧠 Approach: 2D Prefix Sum 🧩 Key Learnings: ● Prefix sums are powerful for optimizing repeated range sum queries. ● 2D prefix sums extend the same idea from arrays to matrices. ● Preprocessing can drastically reduce computation time. ● Avoiding brute force is key in large input problems. ● Matrix problems often become easier with the right transformation. This problem reinforced how preprocessing techniques like prefix sums can turn complex problems into efficient solutions. 🔥 Day 97 complete — sharpening matrix optimization and prefix sum skills. #LeetCode #100DaysOfCode #Java #PrefixSum #Matrix #Algorithms #ProblemSolving #DSA #CodingJourney #Consistency
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