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
Solved Two Sum and Equilibrium Point problems in Java
More Relevant Posts
-
🚀 𝘿𝙖𝙮 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
To view or add a comment, sign in
-
-
🎯 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 57 of #100DaysOfCode 💡 Today, I solved LeetCode Problem #217 – Contains Duplicate 🧩 Given an integer array, the task is simple yet fundamental: 👉 Determine whether any value appears at least twice in the array. 💻 Language: Java ⚡ Runtime: 13 ms — Beats 87.70% 🚀 📉 Memory: 58.28 MB — Beats 63.02% 🧠 Key Learnings: Reinforced my understanding of HashSet and its O(1) lookup time. Learned how sets help efficiently identify duplicates in large datasets. Strengthened array traversal and data structure optimization skills. 🧩 Approach: 1️⃣ Initialize an empty HashSet. 2️⃣ Iterate through each element in the array. 3️⃣ If an element already exists in the set → return true. 4️⃣ Else, add it to the set. 5️⃣ If loop completes, return false. ✅ Complexity: Time: O(n) Space: O(n) ✨ Takeaway: Even basic problems like these teach the power of hash-based structures — simple yet powerful for building optimized systems and preventing redundant computations. #100DaysOfCode #LeetCode #Java #DataStructures #HashSet #ProblemSolving #CodingChallenge #CleanCode #Programming #SoftwareEngineering #TechLearning #Algorithms
To view or add a comment, sign in
-
-
🌟 Day 44 – LeetCode Practice Problem: Product of Array Except Self (LeetCode #238) 📌 Concept: Given an integer array, create a new array where each element equals the product of all other elements except itself, without using division. 🧠 My Approach: First pass → compute prefix products (multiply everything before current index) Second pass → compute suffix products (multiply everything after current index) Combine both to get the result for each index efficiently No extra multiplication array used — optimized and clean logic ⚡ This avoids division and runs in linear time — exactly what the problem demands ✅ 📈 Result: ✅ Accepted ⚡ Runtime: 2 ms (Beats ~87%) 📦 Memory: Efficient usage 💡 Key Learning: This problem reinforces the power of prefix & suffix computation — a common trick in array manipulation + interview favorite. Great way to improve problem-solving without relying on brute force or division. --- 🚀 Growing stronger every day in DSA! #LeetCode #DSA #Java #ProblemSolving #PrefixSuffix #CodingJourney #ArrayProblems #LearningMindset
To view or add a comment, sign in
-
-
#Day5 of #100DaysOfCode Challenge! 🔥 Today’s focus is on strengthening array fundamentals through two challenging problems: Missing Number and First Repeating Element. Problem 1: LeetCode 268 – Missing Number Objective: Identify the missing number in an array containing n distinct numbers ranging from 0 to n. Approach: Utilized the sum formula, n*(n+1)/2, to calculate the expected sum. By subtracting the actual sum of the array elements, the missing number was readily identified. Time Complexity: O(n) | Space Complexity: O(1) This solution is concise, elegant, and exemplifies a clean approach to solving interview problems. Problem 2: First Repeating Element (GFG) Objective: Determine the first repeating element with the smallest index (1-based). Approach: Traversed the array from right to left, utilizing a HashSet to store elements. Whenever a number was encountered that was already present in the HashSet, the index was updated to ensure the smallest possible value. Time Complexity: O(n) | Space Complexity: O(n) Key Takeaway: Recognizing when a mathematical shortcut, such as the sum formula, is applicable versus when a data structure, like a HashSet, is necessary, cultivates strong problem-solving intuition. Balancing simplicity and optimization is crucial for achieving significant growth in problem-solving skills. Thank you Rajesh Gupta for your assistance in guiding me through this process. #100DaysOfCode #LeetCode #DSA #ProblemSolving #Arrays #CodingChallenge #LearningInPublic #Java #Programming
To view or add a comment, sign in
-
-
Day 53 of My DSA Challenge Problem: Find the pair in an array whose sum is closest to and less than or equal to a given target. Approach: Instead of checking every possible pair (O(N²)), I optimized the solution using the Two-Pointer Technique. Sort the array. Initialize two pointers — one at the start and one at the end. Move the pointers based on the sum compared to the target: If the sum is less than or equal to the target, record it and move the left pointer forward. If the sum exceeds the target, move the right pointer backward. This ensures that every pair is checked efficiently, and the closest valid sum is captured. Complexity: Time: O(N log N) (due to sorting) Space: O(1) #Day53 #DSAChallenge #TwoPointers #Sorting #Optimization #ProblemSolving #DSA #Java #CodingChallenge #Algorithms #DataStructures #100DaysOfCode #GeeksforGeeks #LeetCode #ProgrammingJourney #CodingCommunity
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 17 of #50DaysOfLeetCodeChallenge 🚀 🧩 Problem: 88. Merge Sorted Array Today’s problem was all about merging two sorted arrays into one — maintaining non-decreasing order without using extra space! This problem reinforced my understanding of in-place array manipulation and sorting fundamentals. 💡Key Learning: Two-pointer logic or direct insertion can simplify merging. Efficient use of existing array space (nums1) avoids extra memory usage. Sorting the final combined array ensures non-decreasing order. ✅ Solution Highlights: Appended elements of nums2 to the end of nums1. Used Arrays.sort() to maintain sorted order. Time Complexity: O((m + n) log(m + n)) Runtime: 1 ms (Beats 27.22%) ⚡ 🎯 Status: Accepted ✅ — All test cases passed! This problem was a neat reminder of how simple array operations can teach powerful lessons about space optimization and clean algorithmic design. Grateful to Shishir chaurasiya and PrepInsta for their continuous guidance and motivation throughout this challenge! 🙌 #leetcode #coding #java #problemSolving #learning #prepinsta #DSA #50DaysOfLeetCodeChallenge
To view or add a comment, sign in
-
-
✅ Day 120: Shortest Common Supersequence Today’s #nationskillup challenge was a beautiful Dynamic Programming problem 🔗 — focused on finding the length of the smallest string that has both given strings as subsequences. ⚡ Problem Statement: Given two strings s1 and s2, find the length of the shortest string which has both s1 and s2 as its subsequences. 🧠 Example: Input: s1 = "geek", s2 = "eke" Output: 5 Explanation: "geeke" has both "geek" and "eke" as subsequences. 💡 Approach Summary: This problem is based on the Longest Common Subsequence (LCS) concept. If we know the length of LCS, we can derive the length of the Shortest Common Supersequence (SCS) as: SCS=m+n−LCSSCS = m + n - LCSSCS=m+n−LCSwhere: m = length of s1 n = length of s2 We compute LCS using DP with space optimization by maintaining only two arrays — prev and curr. 🔹 Recurrence Relation: if (s1[i-1] == s2[j-1]) curr[j] = 1 + prev[j-1]; else curr[j] = Math.max(prev[j], curr[j-1]); 🔹 Time Complexity: O(m × n) 🔹 Space Complexity: O(n) 🤝 Thanks to GeeksforGeeks and Sandeep Jain Sir for such elegant problems that strengthen core DP skills! 🙌 Shoutout to Tarun Seshank Gorisi for keeping the #nationskillup streak alive 🚀 📚 Course Link: https://lnkd.in/gG3G2QFW #skillupwithgfg #nationskillup #DynamicProgramming #Java #GeeksforGeeks #CodingChallenge #CodeEveryday
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
Congratulations 🎊