Day 11 of Daily DSA 🚀 Solved LeetCode 1394: Find Lucky Integer in an Array ✅ Approach: Iterated through the array and stored the frequency of each element using a HashMap. Then traversed the map to find integers whose value equals their frequency. Among all valid candidates, tracked and returned the maximum lucky integer. This approach ensures clarity and correctness with a straightforward counting strategy. ⏱ Complexity: • Time: O(n) — single pass to count + map traversal • Space: O(n) — extra space for frequency map 📊 LeetCode Stats: • Runtime: 5 ms (Beats 69.53%) ⚡ • Memory: 44.70 MB (Beats 99.01%) A good example of how HashMaps simplify frequency-based problems. #DSA #LeetCode #Java #HashMap #ProblemSolving #DailyCoding #Consistency
LeetCode 1394: Find Lucky Integer in Array with HashMap
More Relevant Posts
-
Day 25 of Practicing DSA on LeetCode Solved: • (540) Single Element in a Sorted Array – Medium Focused on: -Applying binary search on index patterns -Using even–odd index logic to narrow the search space -Achieving O(log n) time with O(1) extra space -Avoiding brute force by trusting array structure This problem showed how sorted data + index patterns = powerful optimizations. Think in patterns, not positions. Consistency over everything. #DSA #Java #LeetCode #BinarySearch #ProblemSolving #Consistency #LearningInPublic
To view or add a comment, sign in
-
-
Today I learned why converting large binary strings using Integer.parseInt() is a bad idea. Solved LeetCode 1404 – Number of Steps to Reduce a Number in Binary Representation to One. Initially, I tried converting the binary string into an integer. Got NumberFormatException. Reason? Binary length > 31 bits → overflow. So instead of converting, I: Processed the string from right to left Simulated carry manually Counted steps without using BigInteger Result: Runtime: 0 ms Beat: 100% Key takeaway: Sometimes the optimal solution is not about bigger data types — It’s about avoiding conversion entirely. #LeetCode #Java #ProblemSolving #DataStructures #Binar
To view or add a comment, sign in
-
-
Day 16/100 – LeetCode Challenge Problem Solved: Binary Tree Level Order Traversal Today’s problem focused on traversing a binary tree level by level. Instead of visiting nodes in depth-first order, the goal is to group nodes according to their depth in the tree. The idea behind the solution is to track the level of each node while traversing the tree. Starting from the root at level 0, each recursive call increases the level for its child nodes. When visiting a node, we check whether a list for that level already exists. If not, we create one; otherwise, we append the node value to the existing level list. By doing this, the traversal naturally organizes nodes into separate lists representing each level of the tree. Time Complexity: O(n) Space Complexity: O(n) Key takeaway: Tree problems often become easier when you track additional context during traversal. In this case, maintaining the current level allows the recursion to build a structured level-by-level result. Day 16 completed. Continuing the consistency streak and strengthening tree traversal concepts. #100DaysOfLeetCode #Java #BinaryTree #TreeTraversal #Algorithms #ProblemSolving
To view or add a comment, sign in
-
-
Day 92/100 – LeetCode Challenge ✅ Problem: #49 Group Anagrams Difficulty: Medium Language: Java Approach: Sorting + HashMap Grouping Time Complexity: O(n × k log k) where k = max string length Space Complexity: O(n × k) Key Insight: Anagrams have identical sorted character sequences. Use sorted string as key to group original strings in HashMap. Solution Brief: Iterated through each string in array. Converted to char array and sorted to get canonical form. Used HashMap with sorted string as key, list of original strings as value. If key exists, add to existing list; otherwise create new list. Collected all values from map into result list. #LeetCode #Day92 #100DaysOfCode #HashMap #Sorting #Java #Algorithm #CodingChallenge #ProblemSolving #GroupAnagrams #MediumProblem #String #Anagram #DSA
To view or add a comment, sign in
-
-
Day 19 of my Data Structures & Algorithms journey. Today’s problem: Same Tree (Binary Tree recursion) on LeetCode. At first glance it looks simple, but it teaches an important idea: Two trees are identical only if both their structure and node values match at every level. Key concept practiced today: Depth-First Search (DFS) with recursion. Step by step the logic becomes: • If both nodes are null → trees match • If one node is null → trees differ • If values differ → trees differ • Otherwise → recursively check left and right subtrees Small problems like these quietly sharpen problem-solving muscles. Consistency > intensity. #LeetCode #DSA #Java #BinaryTree #CodingJourney
To view or add a comment, sign in
-
-
Day 18/100 – LeetCode Challenge Problem Solved: Reverse Linked List Today’s problem focused on reversing a singly linked list. While it looks simple, it’s a fundamental concept that tests pointer manipulation and understanding of linked structures. The idea is to iterate through the list and reverse the direction of each node’s pointer. At every step, we keep track of three things: the current node, the previous node, and the next node. We reverse the link by pointing the current node to the previous one, then move all pointers one step forward. By the end of the traversal, the previous pointer will be pointing to the new head of the reversed list. Time Complexity: O(n) Space Complexity: O(1) Performance: Runtime 0 ms Key takeaway: Linked list problems are all about pointer control. Mastering how pointers move and change direction is essential for solving more complex problems efficiently. Day 18 completed. Staying consistent and reinforcing core data structure fundamentals. #100DaysOfLeetCode #Java #LinkedList #Algorithms #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 19 of Daily DSA 🚀 Solved LeetCode 2089: Find Target Indices After Sorting Array ✅ Approach: Instead of actually sorting the array, I counted: elements less than the target elements equal to the target The starting index is determined by how many elements are smaller than the target, and then indices are built for all equal elements. Simple counting → no extra sorting needed 💡 ⏱ Complexity: • Time: O(n) — single pass • Space: O(1) — excluding output list 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 44.83 MB (Beats 83.41%) A neat example of how thinking beyond “just sort it” can lead to cleaner and faster solutions. #DSA #LeetCode #Java #ProblemSolving #DailyCoding #Consistency #Arrays
To view or add a comment, sign in
-
-
LeetCode 493 — Reverse Pairs Worked on the Reverse Pairs problem today. The task is to count pairs (i, j) such that: • i < j • nums[i] > 2 × nums[j] A brute force solution would check every pair, which results in O(n²) time complexity and becomes inefficient for larger inputs. Approach used :- Instead of checking all pairs directly, I used a modified Merge Sort approach. The idea is: - split the array recursively (similar to merge sort) - both halves become sorted - before merging them, count pairs that satisfy the reverse pair condition - then perform the normal merge step Because both halves are sorted, it becomes possible to count multiple valid pairs efficiently during traversal. Things that became clear: - the problem is closely related to the inversion count pattern - sorting the halves helps reduce unnecessary comparisons - the counting step must happen before merging - overall time complexity improves to O(n log n) Finally got the solution accepted. #leetcode #dsa #algorithms #mergesort #problemSolving #java #learninginpublic
To view or add a comment, sign in
-
-
Day 71/100 – LeetCode Challenge ✅ Problem: #1356 Sort Integers by The Number of 1 Bits Difficulty: Easy Language: Java Approach: Custom Comparator with Bit Counting Time Complexity: O(n log n) Space Complexity: O(n) Key Insight: Sort integers based on number of set bits (1s in binary representation). If bit counts are equal, sort by natural integer order. Use Integer.bitCount() for efficient population count. Solution Brief: Converted primitive array to Integer[] for custom sorting. Applied Arrays.sort() with comparator: Compare bitCount(a) vs bitCount(b) If equal, compare integers directly using a.compareTo(b) Converted back to primitive array. #LeetCode #Day71 #100DaysOfCode #Sorting #Java #Algorithm #CodingChallenge #ProblemSolving #SortByBits #EasyProblem #BitManipulation #Comparator #DSA
To view or add a comment, sign in
-
-
🚀 Day 17 of #100DaysOfCode Solved 75. Sort Colors on LeetCode 🎨 🧠 Key insight: Although this problem is often solved using the Dutch National Flag algorithm, it was interesting to apply QuickSort and see how a general-purpose sorting algorithm still performs efficiently for constrained inputs. ⚙️ Approach: 🔹Applied QuickSort recursively 🔹Chose the middle element as the pivot 🔹Partitioned the array around the pivot 🔹Continued sorting left and right partitions ⏱️ Time Complexity: Average: O(n log n) 📦 Space Complexity: O(log n) (recursive stack) #100DaysOfCode #LeetCode #DSA #Sorting #QuickSort #Java #ProblemSolving #LearningInPublic #CodingJourney
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