You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You are tasked with implementing a system to find the K closest hotels from a given starting point for Booking.com's hotel search feature. The system should efficiently process hotel locations and return the nearest hotels based on geographical distance.
6
+
7
+
### Input Format
8
+
9
+
The system receives:
10
+
1. A list of hotels with their coordinates and metadata
11
+
2. A starting point (latitude, longitude)
12
+
3. An integer K representing the number of closest hotels to find
13
+
14
+
```json
15
+
{
16
+
"hotels": [
17
+
{
18
+
"hotel_id": "H1",
19
+
"name": "Grand Hotel",
20
+
"latitude": 52.3676,
21
+
"longitude": 4.9041,
22
+
"rating": 4.5,
23
+
"price_per_night": 150.00,
24
+
"amenities": ["wifi", "pool", "gym"]
25
+
},
26
+
{
27
+
"hotel_id": "H2",
28
+
"name": "Seaside Resort",
29
+
"latitude": 52.3702,
30
+
"longitude": 4.8952,
31
+
"rating": 4.2,
32
+
"price_per_night": 200.00,
33
+
"amenities": ["wifi", "beach", "restaurant"]
34
+
}
35
+
// ... more hotels
36
+
],
37
+
"start_point": {
38
+
"latitude": 52.3670,
39
+
"longitude": 4.9010
40
+
},
41
+
"k": 5
42
+
}
43
+
```
44
+
45
+
### Requirements
46
+
47
+
1. Implement a function that returns the K closest hotels to the starting point, sorted by distance.
48
+
2. The solution should be efficient for large datasets (millions of hotels).
49
+
3. Consider additional factors that might affect hotel selection:
50
+
- Hotel rating
51
+
- Price per night
52
+
- Available amenities
53
+
- Current availability
54
+
55
+
4. Handle edge cases:
56
+
- Multiple hotels at the same distance
57
+
- Invalid coordinates
58
+
- Empty hotel list
59
+
- K larger than the number of available hotels
60
+
- Hotels with missing or invalid data
61
+
62
+
### Additional Scenarios to Consider
63
+
64
+
1. How would you handle real-time updates to hotel availability?
65
+
2. What if users want to filter results by price range or amenities?
66
+
3. How would you implement caching for frequently searched locations?
67
+
4. How would you handle different distance metrics (e.g., walking distance vs. straight-line distance)?
68
+
5. What if you need to consider traffic conditions or transportation options?
69
+
70
+
### Technical Requirements
71
+
72
+
1. Write code that efficiently finds the K closest hotels
73
+
2. Explain the runtime complexity of your solution
74
+
3. Suggest optimizations for handling large datasets
75
+
4. Consider how to make the system scalable for future requirements
76
+
77
+
### Example Output
78
+
79
+
```json
80
+
{
81
+
"closest_hotels": [
82
+
{
83
+
"hotel_id": "H1",
84
+
"name": "Grand Hotel",
85
+
"distance": 0.3, // in kilometers
86
+
"rating": 4.5,
87
+
"price_per_night": 150.00,
88
+
"amenities": ["wifi", "pool", "gym"]
89
+
},
90
+
{
91
+
"hotel_id": "H2",
92
+
"name": "Seaside Resort",
93
+
"distance": 0.5,
94
+
"rating": 4.2,
95
+
"price_per_night": 200.00,
96
+
"amenities": ["wifi", "beach", "restaurant"]
97
+
}
98
+
// ... more hotels up to K
99
+
],
100
+
"search_metadata": {
101
+
"total_hotels_considered": 1000,
102
+
"search_time_ms": 45,
103
+
"radius_covered_km": 2.5
104
+
}
105
+
}
106
+
```
107
+
108
+
### Evaluation Criteria
109
+
110
+
1. Algorithm efficiency and correctness
111
+
2. Code quality and organization
112
+
3. Handling of edge cases
113
+
4. Runtime complexity analysis
114
+
5. Scalability considerations
115
+
6. Additional features implemented
116
+
7. Problem-solving approach
117
+
118
+
### Notes
119
+
120
+
- The Earth's curvature should be considered when calculating distances
121
+
- The solution should be optimized for both time and space complexity
122
+
- Consider using appropriate data structures for efficient nearest neighbor searches
123
+
- The system should be able to handle frequent updates to hotel data
124
+
- Think about how to make the solution maintainable and extensible
125
+
126
+
### Source
127
+
128
+
This problem is based on a real Booking.com interview experience:
0 commit comments