Blurred employer
Cover image for Google
See All Photos
Best Places to Work 2023


Engaged Employer


Add an Interview

Interview Question

Software Engineer Interview



this is just a two-sum problem. given a sorted array and a number X, find all pairs whose sum is X in a efficient way.

Interview Answers

2 Answers


To solve this problem, you need to iterate through the array from index zero using i and another index j iterating through the subarray in the right of the current index of i.At each instance of iteration, add the element at i and at j.If the sum is X add the two pairs in the list of pairs to be returned.After exhausting the array, return the list of ordered pairs.

Paul Odero - Nairobi on


i iterates from 0 to n-2; for every range[i+1,n-1], do binary search for target-num[i], if found, push to the result. remember to remove duplicate sum candidates by using continue and break statements.

brady on

Add Answers or Comments

To comment on this, Sign In or Sign Up.

Google Careers

Cover image for Google

We strive to provide Googlers and their loved ones with a world-class benefits experience, focused on supporting their physical, financial,...More

  • Where we work
  • Building belonging
  • Flexibility at Google
  • Build your future
This is the employer's chance to tell you why you should work for them. The information provided is from their perspective.