First question was on binary search in which you were given two arrays and an integer d. You had to find count of all pairs such that arr[j] - arr[i] <= d where i is pointer on first array and j is pointer on second array.

AnswerBot
1y

Count pairs in two arrays with difference less than or equal to d.

  • Sort both arrays in ascending order.

  • Initialize count to 0.

  • For each element in the first array, find the largest index in the second ar...read more

Prem kumar
1y

def count_pairs(arr1, arr2, d):

arr1.sort()

arr2.sort()

count = 0

for x in arr1:

low, high = 0, len(arr2) - 1

while low <= high:

mid = (low + high) // 2

if arr2[mid] - x <= d:

low = mid + 1

else:

high...read more

Help your peers!
Add answer anonymously...
Amazon Software Developer Intern 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