🚀 Mastering Java Through LeetCode 🧠 Day 20 of My DSA Journey Today I solved another problem from the LeetCode 75 list to improve my understanding of HashMap and HashSet concepts and strengthen my problem-solving skills. 📌 LeetCode Problem Solved Today: Q.1207 – Unique Number of Occurrences 💡 Problem Statement: Given an integer array arr, return true if the number of occurrences of each value in the array is unique, otherwise return false. 🧩 Example 1: Input: [1,2,2,1,1,3] Output: true 🧩 Example 2: Input: [1,2] Output: false Key Learning: Today I learned how to efficiently solve problems using Hashing techniques: ✔️ Use HashMap to count frequency of each number ✔️ Use HashSet to check if frequencies are unique ✔️ If any frequency repeats → return false 🧠 Approach: 1️⃣ Traverse array and store frequency using getOrDefault() 2️⃣ Traverse map values 3️⃣ Check duplicates using HashSet ⏱️ Complexity: Time Complexity: O(n) Space Complexity: O(n) This problem helped me understand how frequency counting + uniqueness checking works in real interview scenarios. Consistency is the key — solving problems daily to become a better software engineer 💻 #LeetCode #Java #DSA #ProblemSolving #CodingJourney #LearningInPublic #SoftwareDevelopment #Programming #Coding #Tech #Developers #100DaysOfCode #TechCareer #InterviewPreparation #HashMap #HashSet #CodingPractice #PGCP #CDAC #LeetCode75
Mastering Java with LeetCode: Unique Occurrences Problem
More Relevant Posts
-
🚀 Mastering Java Through LeetCode Day 19 Today I solved an interesting problem that helped me strengthen my understanding of Hashing and Data Structures. 📌 LeetCode Q. 2215 – Find the Difference of Two Arrays 🔍 Problem Insight: Given two arrays, the task is to find: ✔️ Elements present in nums1 but NOT in nums2 ✔️ Elements present in nums2 but NOT in nums1 👉 And return only distinct values 💡 Approach I Used: Used HashMap to store unique elements Checked presence using containsKey() (O(1) lookup) Built two result lists efficiently Why this approach? Hashing reduces time complexity and avoids duplicate handling manually. Key Learning: Sometimes choosing the right data structure (HashMap/HashSet) makes the solution clean, fast, and interview-ready. Complexity: Time: O(n + m) Space: O(n + m) Pro Tip: Using HashSet can make the solution even more optimized and readable. Consistency is not about perfection, it's about showing up every day and improving 1% #DSA #Java #LeetCode #CodingJourney #100DaysOfCode #Programming #SoftwareEngineer #Coding #Developers #HashMap #Learning #Tech #PlacementPreparation #CDAC #OpenToWork
To view or add a comment, sign in
-
-
🚀 Mastering Java Through LeetCode 🧠 Day 17 of My DSA Journey Today I solved another problem from the LeetCode list to improve my understanding of arrays and prefix sum concepts. 📌 LeetCode Problem Solved Today: Q.1732. Find the Highest Altitude In this problem, a biker starts a road trip from altitude 0, and we are given an array that represents the gain or loss in altitude between points. The task is to find the highest altitude reached during the trip. Method 1: Using ArrayList (My 1st Approach) I stored all altitudes step by step in an ArrayList and then used Collections.max() to find the highest altitude. Method 2: Optimized Approach (My Second Approach Without Extra Space) Instead of storing all values, we can directly track the maximum altitude while iterating. 💻 Optimized Java Solution class Solution { public int largestAltitude(int[] gain) { int altitude = 0; int maxAltitude = 0; for (int g : gain) { altitude += g; maxAltitude = Math.max(maxAltitude, altitude); } return maxAltitude; } } Example: Input: gain = [-5,1,5,0,-7] Altitudes formed: [0, -5, -4, 1, 1, -6] Highest altitude = 1 Consistent practice is helping me strengthen my DSA and problem-solving skills step by step. #LeetCode #DSA #Java #CodingJourney #ProblemSolving #ArrayList #100DaysOfCode #SPPU #EngineeringLife #TechCommunity #CDAC
To view or add a comment, sign in
-
-
🚀 Mastering Java Through LeetCode 🧠 Day 22 of My DSA Journey Today I solved an interesting matrix-based problem that improved my understanding of arrays and comparison logic. 📌 LeetCode Problem Solved Today: 2352 – Equal Row and Column Pairs Problem Statement: Given an n x n matrix, find how many pairs (row, column) are exactly the same. A pair is valid only if both contain the same elements in the same order. 🧠 Key Idea: Compare each row with every column Check element-by-element equality Count all matching pairs 🔍 Example: Input: [[3,2,1], [1,7,6], [2,7,7]] Output: 1 Matching Pair: Row 2 = Column 1 → [2,7,7] ⚙️ Approach: Traverse all rows Build each column dynamically Compare row[i][k] with column[k][j] If all elements match → increment count ⏱️ Time Complexity: O(n³) (Optimized solution using HashMap possible in O(n²)) What I Learned: Matrix traversal techniques Row vs Column comparison logic Importance of nested loops in grid problems 🔥 Consistency is the key! Every day one problem closer to my goal of becoming a Software Engineer #LeetCode #DSA #Java #CodingJourney #100DaysOfCode #SoftwareEngineer #ProblemSolving #Learning #Tech
To view or add a comment, sign in
-
-
🚀 Mastering Java Through LeetCode 🧠 Day 33 Not all nodes are “Good”… but finding them made me better at Trees 📌 LeetCode Problem Solved: Q.1448 – Count Good Nodes in Binary Tree 💭 Problem Summary: A node is called “Good” if no node on the path from root to it has a greater value. 🎯 Approach: ✔ Used DFS (Depth First Search) ✔ Tracked the maximum value seen so far in the path ✔ If current node ≥ maxSoFar → count it as a Good Node ✔ Updated max and continued recursion 🧠 Key Insight: Instead of storing the full path, just carry maxSoFar — simple yet powerful optimization! 💡 Complexity: ⏱ Time: O(N) 📦 Space: O(H) 🔥 What I Learned: How to maintain state during recursion Clean way to solve tree problems using DFS Thinking in terms of path-based conditions Consistency builds confidence 💪 Day 33 done… Let’s keep going 🚀 #Java #LeetCode #DataStructures #Algorithms #CodingJourney #100DaysOfCode #DSA #Tech #Learning
To view or add a comment, sign in
-
-
🚀 Day 4 of 50 Days Coding Challenge Today I solved a problem on Hashing Pattern 🔹 Problem: Two Sum 🔹 Approach: First tried brute force using nested loops (checking all pairs) Then optimized using HashMap (Hashing concept) to reduce time complexity 🔹 Key Learning: Instead of checking every pair, we can store values and directly check if the required complement exists. This reduces time complexity from O(n²) → O(n) 🚀 Also learned an important concept: 👉 need = target - current element 🔹 Time Complexity: O(n) 🔹 Code (Java): import java.util.*; class Solution { public int[] twoSum(int[] nums, int target) { HashMap<Integer, Integer> map = new HashMap<>(); for(int i = 0; i < nums.length; i++) { int need = target - nums[i]; if(map.containsKey(need)) { return new int[]{map.get(need), i}; } map.put(nums[i], i); } return new int[]{-1, -1}; } } 💡 Consistency > Motivation #coding #leetcode #100DaysOfCode #java #programming #dsa #learning #hashmap
To view or add a comment, sign in
-
🚀 Mastering Java Through LeetCode 🧠 Day 21 of My DSA Journey 📌 Problem Solved: Q.1657 – Determine if Two Strings Are Close 💡 Problem Insight: At first glance, this problem looks like a simple string comparison… But it actually tests your understanding of patterns, hashing, and transformations. We are allowed to: ✔ Swap characters (change order) ✔ Transform characters (swap frequencies) 🧠 Key Learning: Two strings are "close" if: ✅ They have the same set of characters ✅ Their frequency distribution matches (order doesn’t matter) 👉 That means: Order is irrelevant Only character presence + frequency pattern matters 🔍 Approach I Used: 1️⃣ Checked if lengths are equal 2️⃣ Counted frequency using arrays 3️⃣ Verified both strings have same unique characters 4️⃣ Sorted frequency arrays and compared ⚡ Example: word1 = "cabbba" word2 = "abbccc" ✔ Same characters → {a, b, c} ✔ Frequencies match after sorting → [1,2,3] 👉 Result: true Tech Stack: Java Concepts Covered: Hashing | Arrays | Frequency Count Takeaway: This problem taught me how to: Think beyond direct comparison Focus on data patterns instead of structure Consistency + Practice = Growth #LeetCode #DSA #Java #CodingJourney #100DaysOfCode #ProblemSolving #Developers #SoftwareEngineer #Learning #Growth #CDAC #PlacementPreparation #Tech
To view or add a comment, sign in
-
-
Day 38 – 44 of my Frontlines EduTech (FLM) AI-Powered Java Full Stack Journey Day 38: Started learning Collections in Java. Focused on ArrayList and how it stores dynamic data. Understood how it is different from arrays. Day 39: Learned about Iterator. Used it to traverse elements in collections. It made looping through data more clean and flexible. Day 40: Explored Set interface. Learned that it stores only unique elements. Good for removing duplicates from data. Day 41: Learned Map in Java. Stores data in key-value pairs. Very useful for real-world applications. Day 42: Covered Enum and Command Line Arguments. Also learned Static and Instance Blocks. Understood when and how they are executed. Day 43: Learned Clone, Comparator, and Comparable. Used for copying objects and sorting data. Important for customizing sorting logic. Day 44: Solved problem on frequency of characters. Used logic with collections to count occurrences. Good practice for improving problem-solving skills. Consistent learning, step by step. Fayaz S 🔗 Github: https://lnkd.in/gV_uis3J #Java #Collections #CodingJourney #100DaysOfCode #LearnJava #FullStack 🚀
To view or add a comment, sign in
-
-
Starting my daily coding challenge series to stay consistent and sharpen problem-solving skills. Problem Statement: Given an integer `day` representing the day number of the week, print the corresponding day name. - The week starts from Monday (1) and ends on Sunday (7). - If the input is less than 1 or greater than 7, print "Invalid." - Ensure only the first letter is capitalized. Example: Input: `3` Output: `Wednesday` Input: `8` Output: `Invalid` Try solving it using: - Conditional statements Consistency beats motivation. See you in Day 2. #100DaysOfCode #CodingChallenge #JavaScript #Python #Java #CPP #ProblemSolving #Developers #SoftwareEngineer #LearnToCode #DSA
To view or add a comment, sign in
-
Turning concepts into confidence 💻✨ Recently, I focused on strengthening my core understanding of Java fundamentals — because a strong foundation is what builds great developers. 📌 Topics I explored: ✔ Data Types (Primitive & Non-Primitive) ✔ Type Casting (Implicit & Explicit) ✔ Wrapper Classes ✔ Integer to Binary Conversion ✔ String Handling Basics While these may seem like basic concepts, they play a crucial role in writing efficient, error-free, and optimized programs. Understanding how data is stored, converted, and processed gives a whole new perspective on problem-solving. What I realized is — coding is not just about writing syntax, it’s about understanding the logic behind every step. The more clarity we build in fundamentals, the easier it becomes to tackle complex problems later. Consistency is the key 🔑 Learning a little every day is helping me grow step by step in my developer journey. Looking forward to diving deeper into advanced Java concepts and building real-world applications 🚀 #Java #Programming #DeveloperJourney #Learning #Coding #TechSkills #StudentLife #Consistency #Growth #GQT
To view or add a comment, sign in
-
🚀 Day 20 of #100DaysOfCode – Java DSA Journey Today was all about understanding some of the most important Java Collections — the building blocks for writing efficient code 💡 📚 Topic: ArrayList vs HashSet vs HashMap At first glance, they may look similar… but each serves a completely different purpose 👇 🔹 ArrayList ✔️ Ordered (maintains insertion order) ✔️ Allows duplicates ✔️ Index-based access 🧠 When to use? When order matters When you need to access elements using index When duplicates are allowed 🔹 HashSet ✔️ Unordered ✔️ No duplicates allowed ✔️ Faster lookups (O(1) average) 🧠 When to use? When you only care about unique elements When checking existence is important 🔹 HashMap ✔️ Stores data in key-value pairs ✔️ Keys are unique, values can be duplicated ✔️ Very fast operations (O(1) average) 🧠 When to use? When mapping relationships (like frequency count, indexing, caching) When you need quick access using keys 💭 Key Insight: Choosing the right data structure = cleaner code + better performance ⚡ Today made me realize: Not every problem needs a loop Sometimes, the right collection can reduce complexity instantly 📌 What I Learned Today: ✅ Difference between ArrayList, HashSet, and HashMap ✅ When to use each data structure ✅ Importance of avoiding duplicates efficiently ✅ Writing optimized logic using collections Consistency check ✅ Clarity improved ✅ Confidence growing 📈 Let’s keep building 🚀 Day 21 coming soon! #Java #DSA #100DaysOfCode #CodingJourney #LearningInPublic #DeveloperLife #Programmer #CodingLife #SoftwareEngineering #ComputerScience #TechJourney #ProblemSolving #Algorithms #DataStructures #JavaDeveloper #CodeDaily #Consistency #GrowthMindset #SelfImprovement #StudentLife #EngineeringStudent #FutureEngineer #CodeNewbie #KeepLearning #BuildInPublic #Motivation #Discipline #DailyProgress #NeverGiveUp
To view or add a comment, sign in
-
Explore related topics
- LeetCode Array Problem Solving Techniques
- Approaches to Array Problem Solving for Coding Interviews
- Java Coding Interview Best Practices
- Tips for Coding Interview Preparation
- Why Use Coding Platforms Like LeetCode for Job Prep
- Common Algorithms for Coding Interviews
- Strategies for Solving Algorithmic Problems
- Common Data Structure Questions
- Key DSA Patterns for Google and Twitter Interviews
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