Trying to minimize iteration
Hello community members i am trying to minimize iteration in my code lazy friends as i am getting time limited exceeded error in 1 test case any help will be appreciated thanks. Problem is:: Several friends live along a straight street. They are friends, thus they enjoy visiting each other. However, they are lazy so none of them wants to visit a friend living more than maxDist meters away from them. Given array houses representing coordinates of points where the friends live (in meters) and an integer maxDist, return an array representing the number of friends each person would be willing to visit. Example For houses = [1, 2, 4, 8, 10] and maxDist = 5, the output should be lazyFriends(houses, maxDist) = [2, 2, 3, 2, 1]. houses: [-5, 0, 5, 10, 15] maxDist: 10 Expected output [2, 3, 4, 3, 2] https://code.sololearn.com/cZSdCA90v1eP/?ref=app