"Day 9: Valid Anagram solution in Java"

🚀 Day 9 of 100 Days of LeetCode 🧩 Problem: #242. Valid Anagram 💻 Difficulty: Easy 🔍 Concept: Check whether two strings are anagrams — i.e., they contain the same characters in the same frequency, just rearranged. ⚙️ Approach Used: Used a frequency array of size 26 to count occurrences of each character in the first string. Decreased counts while scanning the second string. If all frequencies end up zero ➜ both strings are anagrams ✅ 🧠 Key Learnings: Practiced frequency array patterns for string problems. Learned to avoid sorting-based solutions for better time complexity (O(n) instead of O(n log n)). 💻 Code (Java): class Solution { public boolean isAnagram(String s, String t) { int[] freq = new int[26]; for (char c : s.toCharArray()) freq[c - 'a']++; for (char c : t.toCharArray()) freq[c - 'a']--; for (int f : freq) if (f != 0) return false; return true; } } 💬 Reflection: Small wins count too! Even the simplest problems help in strengthening your logical foundation and pattern recognition. #100DaysOfLeetCode #Day9 #ProblemSolving #Java #LeetCode #DSA #CodingChallenge #LearningEveryday

  • text

To view or add a comment, sign in

Explore content categories