Two Sum II - Java Solution with Two Pointer Technique

100 Days of Coding Challenge – Day 24 📌 Problem: Two Sum II – Input Array Is Sorted 💻 Language: Java 🧠 Concept Used: Two Pointer Technique 🔍 Platform: LeetCode Today’s challenge was to find two numbers in a sorted array that add up to a given target and return their 1-indexed positions. The problem guarantees exactly one valid solution and requires constant extra space. Example: Input: numbers = [2,7,11,15], target = 9 Output: [1,2] Approach: ✔ Use two pointers — one at the start (left) and one at the end (right) ✔ Calculate the sum of both elements ✔ If the sum equals the target → return their indices ✔ If the sum is smaller → move left forward ✔ If the sum is larger → move right backward Time Complexity: O(n) Space Complexity: O(1) 🔗 Problem Link: https://lnkd.in/gcM_dBA7 🔗 Code: https://lnkd.in/gaUrS-Ne #100DaysOfCode #Day24 #Java #DSA #LeetCode #TwoPointers #Arrays #ProblemSolving #CodingJourney

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories