🚀 𝘿𝙖𝙮 98 𝙤𝙛 100 𝘿𝙖𝙮𝙨 - 𝙅𝙖𝙫𝙖 ✅problem : Degree of an Array(Question No:697) 📍platform: LeetCode 🔍Level: Easy. ✅ LeetCode Problem: Degree of an Array (#697) Successfully solved with a runtime of 10 ms (Beats 93.22%) 🎯 🔍 Approach: Used a HashMap to track each number’s ➤ First occurrence index ➤ Last occurrence index ➤ Frequency count Calculated the degree (maximum frequency) of the array. Found the shortest subarray that has the same degree. 💡 Key Insight: By storing indices and counts efficiently, we can compute the shortest subarray in O(n) time — a neat combination of map tracking and logic optimization. #LeetCode #Java #CodingChallenge #ProblemSolving #DataStructures #Algorithms #LearningJourney #HashMap #Programming #CodeNewbie #WomenInTech
Solved LeetCode #697: Degree of an Array in Java with HashMap
More Relevant Posts
-
🎯 Day 7 of #365DaysofDSA Today I solved “Maximum Depth of Binary Tree” (LeetCode #104) 🌳 💡 Concepts used: • Recursion • Depth Calculation in Binary Trees ✨ Approach Summary: Used a recursive approach to find the longest path from the root node down to the farthest leaf node. For each node: 1️⃣ Recursively find the maximum depth of its left and right subtrees. 2️⃣ The current node’s depth = max(leftDepth, rightDepth) + 1. This elegant recursive solution divides the problem into smaller subproblems — calculating depth for subtrees and combining the results. 🚀 Key takeaway: Recursive thinking simplifies complex tree problems by leveraging the natural hierarchical structure of binary trees. 🌱 #Day7 #DSA #LeetCode #Java #BinaryTree #Recursion #ProblemSolving #CodingJourney #Programming #LearnByDoing #MaximumDepthOfBinaryTree
To view or add a comment, sign in
-
-
Day 6 of #100DaysOfCode Today’s exploration of two classic array problems, Two Sum and Equilibrium Point, enhanced my comprehension of hashing, prefix sums, and optimization techniques. Problem 1: Two Sum (LeetCode #1) Objective: Identify two numbers that sum to a specified target and return their indices. Approach: Utilizing a one-pass HashMap, I stored each element’s index and promptly verified if the complement (target minus the current element) already existed. This approach ensured both efficiency and elegance. Time Complexity: O(n) Space Complexity: O(n) Problem 2: Equilibrium Point (GFG) Objective: Determine the index where the sum of elements on the left equals the sum on the right. Approach: By calculating the total sum, I maintained a running leftSum while dynamically updating the rightSum in a single pass. Time Complexity: O(n) Space Complexity: O(1) Key Takeaways: These problems demonstrated how clear mathematical logic combined with appropriate data structures can yield powerful yet straightforward solutions. Each line of code imparts a novel perspective on efficient problem-solving. Thank you Rajesh Gupta all for your guidance and support! 🙌 hashtag #100DaysOfCode #LeetCode #DSA #ProblemSolving #Arrays #CodingChallenge #LearningInPublic #Java #Programming
To view or add a comment, sign in
-
-
Day 21 — Next Greater Numerically Balanced Number Problem: 2048. Next Greater Numerically Balanced Number Difficulty: Medium A number is called numerically balanced if for every digit d in it, there are exactly d occurrences of that digit. For example: 22 → two 2’s ✅ 1333 → one 1, three 3’s ✅ 1233 → ❌ (only two 3’s, not three) The task was to find the smallest numerically balanced number that’s strictly greater than a given n. The trick here? Instead of dynamically generating all possibilities, we can precompute all balanced numbers and simply use binary search to find the next one — making the lookup super efficient. #Day21 #LeetCode #Java #100DaysOfCode #ProblemSolving #CodingJourney #Algorithms #BinarySearch #Precomputation #Programming
To view or add a comment, sign in
-
-
🔥 Day 79 of #100DaysDSAChallenge 📌 Topic: Array — Minimum Moves to Equal Array Elements ✅ Problem Solved on #LeetCode: 453. Minimum Moves to Equal Array Elements (🟠 Medium) 💡 Key Learnings: • Understood that incrementing (n−1) elements is equivalent to decrementing one element. • Learned how to derive the formula using the smallest element as a reference point. • Strengthened problem-solving with array manipulation and mathematical reasoning. • Enhanced understanding of optimization — solving in O(n) time and O(1) space. 🚀 Stay Consistent: Daily practice turns effort into skill and skill into success. 🏷️ #Day79 #100DaysChallenge #100DaysDSAChallenge #LeetCode #Java #CodingChallenge #ProblemSolving #DataStructures #Algorithms #Arrays #Programming #LearningJourney #10kCoders #10000Coders #Consistency #LogicBuilding
To view or add a comment, sign in
-
-
✅Day 71 of #100DaysOfLeetCode 1.📌Problem: Number of 1 Bits Given a positive integer n, write a function that returns the number of set bits in its binary representation (also known as the Hamming weight). 2.🟢 Difficulty: Easy 3.📍Topic: Bit Manipulation 4.🎯 Goal: Find the number of '1' bits present in the binary representation of the given integer n. 5.🧠 Key idea: Approach 1: Keep dividing n by 2 and count if the remainder is 1. This counts the number of 1's in binary form by repeatedly checking and incrementing a counter. A simple while-loop approach that efficiently solves the problem for any positive integer n.image.jpg #100DaysOfCode #LeetCode #CodingChallenge #BitManipulation #DataStructures #Algorithms #Java #Programming #Tech #CodeNewbie #InterviewPrep #LeetCodeEasy #ProblemSolving #LearnToCode #Developer
To view or add a comment, sign in
-
-
✅Day 80 of #100DaysOfLeetCode 1.📌Problem: Set Mismatch You are given an array that represents a set of integers from 1 1 to n n, but due to an error, one number is duplicated and another is missing. The task is to find the duplicated number and the missing number and return them as an array. 2.🟢 Difficulty: Easy 3.📍Topic: Hashing,Array 4.🎯 Goal: Find the number that occurs twice and the number that is missing, then return them in an array. 5.🧠 key idea: Approach 1: Use a HashMap to count occurrences of each number in the input array. Identify the duplicated number by finding the one which appears twice. Compute the total sum expected (n(n+1)/2 n(n+1)/2) and compare with the actual sum (excluding the duplicate). The missing number equals the difference between the expected total and the corrected actual sum. Return the duplicate and missing numbers as the result array. #LeetCode #100DaysOfCode #CodingChallenge #Java #Programming #InterviewPrep #Algorithms #DataStructures #Hashing #ProblemSolving #Array #SoftwareEngineering #TechCareers #LearnToCode #CodeNewbie #DailyCode #ChallengeYourself
To view or add a comment, sign in
-
-
💻 Day 69 of #LeetCode100DaysChallenge Solved LeetCode 264: Ugly Number II a dynamic programming problem that improves sequence generation and pointer-based optimization skills. 🧩 Problem: An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5. Given an integer n, return the n-th ugly number. 💡 Approach — Dynamic Programming with Three Pointers: 1️⃣ Maintain an array dp where dp[i] stores the i-th ugly number. 2️⃣ Use three pointers p2, p3, and p5 to track multiples of 2, 3, and 5 respectively. 3️⃣ At each step, choose the smallest of dp[p2]*2, dp[p3]*3, and dp[p5]*5 as the next ugly number. 4️⃣ Increment the corresponding pointer(s) to avoid duplicates. 5️⃣ Continue until the nth ugly number is found. ⚙️ Complexity: Time: O(N) — one pass to generate all ugly numbers Space: O(N) — for storing the sequence ✨ Key Takeaways: ✅ Strengthened understanding of pointer-based DP techniques. ✅ Learned how to efficiently generate sorted multiplicative sequences. ✅ Practiced optimization over brute-force factor checking. #LeetCode #100DaysOfCode #Java #DynamicProgramming #TwoPointers #Math #DSA #ProblemSolving #CodingJourney #WomenInTech
To view or add a comment, sign in
-
-
🗓 Day 1 / 100 – #100DaysOfLeetCode 📌 Problem 637: Average of Levels in Binary Tree Given the root of a binary tree, the task was to return the average value of the nodes at each level in an array. For example, Input: [3,9,20,null,null,15,7] Output: [3.00000, 14.50000, 11.00000] 🧠 My Approach: Used Breadth-First Search (BFS) traversal to process the tree level by level: Initialized a queue and pushed the root node. For each level, iterated through all nodes, accumulating their values. Calculated the average of that level and added it to the result list. Continued until all levels were processed. This approach effectively uses a queue to handle each level’s nodes in order. ⏱ Time Complexity: O(n) – every node is visited once 💾 Space Complexity: O(w) – where w is the maximum width of the tree 💡 Key Learning: This problem strengthened my understanding of level-order traversal using BFS. It showed how queues can efficiently help process hierarchical structures like trees — not just for traversal, but also for aggregating information level-wise 🌳 #100DaysOfLeetCode #LeetCodeChallenge #Java #ProblemSolving #BinaryTree #BFS #DataStructures #Algorithms #DSA #CodingJourney #CodeEveryday #SoftwareEngineering #LearningInPublic #DeveloperJourney #TechStudent #CodingCommunity #LogicBuilding #CareerGrowth #KeepLearning #Programmer #TechCareer
To view or add a comment, sign in
-
-
✅Day 52 : Leetcode 1539 - Kth Missing Positive Number #60DayOfLeetcodeChallenge 🚀 Problem Statement Given a sorted array of positive integers arr and an integer k, find the kth positive integer that is missing from the array. 🧩 Example: Input: arr = [2,3,4,7,11], k = 5 Output: 9 Explanation: The missing positive numbers are [1,5,6,8,9,10,12,...]. The 5th missing number is 9. 💡 My Approach I used Binary Search to efficiently find the position where the kth missing number lies. For each index mid, the count of missing numbers till that index is arr[mid] - (mid + 1). If the missing count is less than k, it means the missing number lies to the right. Otherwise, move left. Finally, return low + k, which gives the exact missing number. ✅ This avoids checking each number sequentially and works efficiently even for large arrays. ⏱️ Time Complexity O(log n) — due to binary search. #Coding #DSA #BinarySearch #ProblemSolving #LeetCode #Java #Programming #DataStructures #Algorithms #Learning
To view or add a comment, sign in
-
-
Day 54 of My DSA Challenge Problem: Count the number of pairs in an array whose sum equals a given target. Approach: Instead of the brute-force O(N²) method that checks every pair, I optimized the solution using a HashMap for frequency counting. Traverse the array once. For each element, check if (target - current element) exists in the map. If it does, it means those previous elements can form valid pairs with the current one. Update the frequency of the current element in the map. This smart use of a HashMap allows counting pairs in a single pass. Complexity: Time: O(N) Space: O(N) Key Insight: Using a frequency map turns an otherwise nested loop problem into a single-pass efficient solution — a common and elegant trick in array-based problems. #Day54 #DSAChallenge #HashMap #Optimization #ProblemSolving #Java #CodingChallenge #Algorithms #DataStructures #100DaysOfCode #GeeksforGeeks #LeetCode #CodingJourney #ProgrammersLife #TechLearning
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