Solved Two Sum and Equilibrium Point problems in Java

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

  • text

Congratulations 🎊

Like
Reply

To view or add a comment, sign in

Explore content categories