numOfHouse = 5
houseList = [[3, 7], [1, 9], [2, 0], [5, 15], [4, 30]]
[4, 5]
def findLargestLand(numOfHouse, houseList):
# Sort the house list based on position
houseList.sort(key=lambda x: x[1])max_distance = 0
result = []# Find the pair with the largest distance
for i in range(1, len(houseList)):
distance = houseList[i][1] – houseList[i-1][1]
if distance > max_distance:
max_distance = distance
result = [houseList[i-1][0], houseList[i][0]]# Return the result in ascending order
return sorted(result)# Example usage
numOfHouse = 5
houseList = [[3, 7], [1, 9], [2, 0], [5, 15], [4, 30]]
print(findLargestLand(numOfHouse, houseList))houseList by the position of the houses using Python’s sort() function. This ensures that we can easily calculate distances between consecutive houses.max_distance and store the house numbers of the pair with the largest distance.houseList takes O(nlogn)O(n \log n)O(nlogn), where nnn is the number of houses.