Two Sum Problem Statement

Given an array A of size N, sorted in non-decreasing order, return two distinct indices whose values add up to a given 'target'. The array is 0 indexed. If multiple answers exist, return any pair of indices.

Input:

 A list of test cases 
Each test case includes:
'N' (number of elements) and 'Target' (desired sum)
Followed by elements of array 'A'

Output:

 Indices (two for each test case) which add up to the 'target'. 

Example:

Input:
 T = 1 
N = 5, Target = 8
A = [1, 2, 3, 4, 5]
Output:
 2 4 
Explanation:

For array A, indices 2 and 4 jointly make the target sum: 3 + 5 == 8, so return 2 4.

Constraints:

  • 1 ≤ T ≤ 1000
  • 1 ≤ N ≤ 100000
  • -1000 ≤ A[i] ≤ 1000
  • Total sum ΣN ≤ 300000
  • Time limit: 1 second
Note:

You need not print anything explicitly as it's handled in the system, simply implement the necessary function to return the result.

AnswerBot
4d

Given a sorted array, find two distinct indices whose values add up to a given target.

  • Use two pointers approach to find the indices that add up to the target.

  • Start with one pointer at the beginning an...read more

Help your peers!
Add answer anonymously...
Bosch Global Software Technologies Associate Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter