Just learned something that clicked for me today! 💡 The Frequency Counting Pattern in Java — one of the most used patterns in DSA! The idea is simple: → Use HashMap to count occurrences → Key = element, Value = count → One loop. Done. O(n)! HashMap<Integer, Integer> freq = new HashMap<>(); for (int num : arr) { freq.merge(num, 1, Integer::sum); } This single pattern helped me solve: ✅ Finding duplicates ✅ Most/least frequent element ✅ Character frequency in strings ✅ Two Sum Brute force = O(n²) 😴 HashMap pattern = O(n) 🚀 Still learning and loving every bit of it! Building a Banking System to practice all concepts 🏦 #Java #DSA #LearningInPublic #100DaysOfCode #JavaDeveloper #DataStructures #Programming
sushmitha vurutur sridhar’s Post
More Relevant Posts
-
Day 66 of #100DaysOfLeetCode 💻✅ Solved #3427. Sum of Variable Length Subarrays problem in Java. Approach: • Iterated through each index of the array • Determined the starting index using i - nums[i] • Ensured the start index does not go below 0 • Calculated sum of elements from start to current index i • Added each subarray sum to the total Performance: ✓ Runtime: 1 ms (Beats 99.90% submissions) ✓ Memory: 45.22 MB (Beats 56.30% submissions) Key Learning: ✓ Practiced handling variable-length subarrays ✓ Improved understanding of index-based range calculations ✓ Strengthened nested loop logic for array problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #PrefixSum #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 62 of My Java DSA Journey✨ Today I solved an important Binary Tree problem: 💡 Vertical Order Traversal 🧠 Approach: • Used level order traversal (BFS) with a queue • Tracked horizontal distance (hd) for each node • Left child → hd - 1, Right child → hd + 1 • Stored nodes in a HashMap based on their hd • Maintained min & max hd to print nodes from left to right 🔍 Key Insight: Nodes lying on the same vertical line share the same horizontal distance. By grouping nodes using hd, we can easily print the tree vertically. ⚡ What I learned: • Applying BFS with extra information (hd tracking) • Mapping tree nodes using HashMap effectively • Understanding vertical structure of binary trees • Importance of traversal order in output formation 🔥 Complexity: • Time: O(n) • Space: O(n) 🎯 Takeaway: Tree problems become easier when you visualize node positions. Adding a small concept like horizontal distance can completely change how you solve traversal problems. #Day62 #90DaysOfCoding #DSA #BinaryTree #Java #ProblemSolving #VerticalTraversal
To view or add a comment, sign in
-
-
🚀 Day 45 / 180 – DSA with Java 🚀 📘 Topic Covered: Arrays & Two-Pointer Technique 🧩 Problem Solved: Merge Sorted Array Problem: Given two sorted arrays, merge the second array into the first one as a single sorted array. Approach: Started comparing elements from the end of both arrays and filled the first array from the last position backwards. This avoided shifting elements and enabled an efficient in-place merge. Key Learning: ✔️ Using reverse traversal for in-place operations ✔️ Applying two-pointer technique effectively ✔️ Merging sorted data in O(m + n) time If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Arrays #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 69 of #100DaysOfLeetCode 💻✅ Solved #349. Intersection of Two Arrays problem in Java. Approach: • Iterated through each element of the first array • Checked if the element exists in the second array • Used a temporary array to store intersection elements • Ensured no duplicates by checking already added elements • Copied the result into a final array of correct size Performance: ✓ Runtime: 4 ms (Beats 35.60%) ✓ Memory: 44.41 MB (Beats 96.71%) Key Learning: ✓ Practiced array traversal using nested loops ✓ Learned how to handle duplicates manually ✓ Improved understanding of set-like operations without using extra data structures Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 76 of #100DaysOfLeetCode 💻✅ Solved #33. Search in Rotated Sorted Array problem in Java. Approach: • Applied Binary Search on rotated array • Checked which half is sorted at each step • Reduced search space based on target position Performance: ✓ Runtime: 0 ms (Beats 100.00% submissions) 🚀 ✓ Memory: 43.80 MB (Beats 70.96% submissions) Key Learning: ✓ Mastered searching in rotated sorted arrays ✓ Improved Binary Search decision-making ✓ Learned efficient handling of edge cases Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinarySearch #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 10 – Race Condition & Synchronization in Java After learning multithreading, I explored a common issue: Race Condition 👉 It happens when multiple threads access and modify shared data at the same time. Example: class Counter { int count = 0; void increment() { count++; } } If multiple threads call "increment()" simultaneously: 👉 Expected: consistent count 👉 Reality: unpredictable results 💡 Why? Because "count++" is not atomic (it involves multiple steps internally) --- 👉 Solution: Synchronization synchronized void increment() { count++; } ✔ Ensures only one thread executes the method at a time ✔ Prevents data inconsistency ⚠️ Insight: Synchronization solves the problem, but excessive use can impact performance. 💡 Real takeaway: - Multithreading = powerful - But without control → leads to subtle bugs - Balance between safety and performance is key #Java #BackendDevelopment #Multithreading #Synchronization #LearningInPublic
To view or add a comment, sign in
-
Day 89 of #100DaysOfLeetCode 💻✅ Solved #15. 3Sum problem in Java. Approach: • Sorted the array first • Fixed one element and used Two Pointers for the rest • Skipped duplicates to avoid repeated triplets • Adjusted pointers based on sum comparison Performance: ✓ Runtime: 30 ms (Beats 87.77% submissions) ✓ Memory: 59.02 MB (Beats 77.30% submissions) Key Learning: ✓ Mastered Two Pointer technique with sorting ✓ Learned handling duplicates efficiently ✓ Improved problem-solving for combination-based problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #TwoPointers #Arrays #Sorting #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 68 of #100DaysOfLeetCode 💻✅ Solved #977. Squares of a Sorted Array problem in Java. Approach: • Traversed the array and squared each element • Used Arrays.sort() to sort the squared values • Returned the sorted array as the result Performance: ✓ Runtime: 10 ms (Beats 37.38% submissions) ✓ Memory: 47.98 MB (Beats 18.78% submissions) Key Learning: ✓ Practiced array transformation and sorting ✓ Learned how squaring affects order in sorted arrays ✓ Understood the importance of optimizing from O(n log n) to O(n) using two pointers Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #Sorting #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 77 of #100DaysOfLeetCode 💻✅ Solved #153. Find Minimum in Rotated Sorted Array problem in Java. Approach: • Used Binary Search to find minimum element • Compared mid with right to decide direction • Reduced search space until pointers converged Performance: ✓ Runtime: 0 ms (Beats 100.00% submissions) 🚀 ✓ Memory: 43.62 MB (Beats 78.18% submissions) Key Learning: ✓ Strengthened Binary Search on rotated arrays ✓ Learned how to identify unsorted portion efficiently ✓ Improved optimization over linear search Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinarySearch #Arrays #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 related topics
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