Duplicate Hotel Listings
0:00:00
Let’s say at Agoda we have hotel listings from several suppliers, and some of them are the same physical property listed twice. Write a function called find_duplicates that takes listings as (listing_id, name, lat, lon) tuples and returns the groups of listing ids that are the same property.
Rules - Two listings match when they are at most 100 meters apart and their name similarity is at least 0.5. If A matches B and B matches C, all three are the same property. - Name similarity is the number of words two names share divided by the number of distinct words across both, after lowercasing and splitting on anything that isn’t a letter or digit. - Measure distance along the Earth’s surface with a radius of 6,371 km. - Return only groups of 2 or more, each sorted, with the groups ordered by smallest id.
Example:
Input:
listings = [
(1, "Hotel Sakura Shinjuku", 35.6938, 139.7034),
(2, "Sakura Hotel", 35.6941, 139.7038),
(3, "Sakura Hotel & Spa", 35.6946, 139.7044),
(4, "Park Hyatt Tokyo", 35.6856, 139.6909),
(5, "Sakura Hotel", 35.7101, 139.8107),
(6, "Tokyu Stay Shinjuku", 35.6939, 139.7036),
]
Output:
def find_duplicates(listings) -> [[1, 2, 3]]
.
.
.
.
Comments