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
4mo

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!
Select
Add answer anonymously...

Bosch Global Software Technologies Associate Software Engineer interview questions & answers

An Associate Software Engineer was asked 5mo agoQ. Write a program to generate the Fibonacci sequence.
An Associate Software Engineer was asked 9mo agoQ. Write a simple string-based coding question with implementation.
An Associate Software Engineer was asked 10mo agoQ. What is the difference between malloc and calloc?

Popular interview questions of Associate Software Engineer

An Associate Software Engineer was asked 8mo agoQ1. Write a simple string-based coding question with implementation.
An Associate Software Engineer was asked 10mo agoQ2. What is the difference between malloc and calloc?
An Associate Software Engineer was asked 10mo agoQ3. Are you comfortable working in Bangalore?
Bosch Global Software Technologies Associate Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits