Back to problems

Minimum Distance Between People and Cakes

Algorithm · Google · Easy

Create a method that finds the smallest separation between any person and any cake. It receives two integer arrays: one listing person locations and the other listing cake locations. Each array is already ordered from lowest to highest. Return an integer representing the minimum distance. All locations lie along one shared line. Your implementation must run in O(N) time. Test cases: People positions: [2, 6, 9], Cake positions: [3, 8]. Output: 1 People positions: [2, 4, 5],…

Checking your access…