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...
Top Amazon Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Top HR questions asked in Amazon Software Developer Intern
Stay ahead in your career. Get AmbitionBox app
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
Get AmbitionBox app