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!
Add answer anonymously...
Top Associate Software Engineer Interview Questions Asked at Bosch Global Software Technologies
Q. Write a program to generate the Fibonacci sequence.
Q. Write a simple string-based coding question with implementation.
Q. What is the difference between malloc and calloc?
Interview Questions Asked to Associate Software Engineer at Other Companies
Top Skill-Based Questions for Bosch Global Software Technologies Associate Software Engineer
Data Structures Interview Questions and Answers
250 Questions
Algorithms Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
C++ Interview Questions and Answers
150 Questions
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

