Activities Within Travel Radius
Updated
Problem statement
A client stays at home = [x, y] and is willing to travel at most radius in a day. Activity i is at the point activities[i] = [x, y]. The distance to an activity is the straight-line distance between the two points.
An activity can be suggested when its distance from home is at most radius. An activity exactly radius away counts.
Return the indices (starting at 0) of all activities that can be suggested, from the closest to the farthest. When two activities are the same distance away, the one with the smaller index comes first. If no activity is close enough, return an empty array.
The number of activities the client can do in a day is the length of the returned array.
Function
suggestActivities(home: int[], activities: int[][], radius: int) → int[]Examples
Example 1
home = [2,1]activities = [[5,5],[2,3],[9,1],[0,0],[-2,1]]radius = 5return = [1,3,4,0]Squared distances from home (2, 1): activity 0 at (5, 5) gives 3*3 + 4*4 = 25, activity 1 gives 0 + 2*2 = 4, activity 2 gives 7*7 = 49, activity 3 gives 2*2 + 1*1 = 5 and activity 4 gives 4*4 = 16. The radius is 5, so the limit is 25. Activity 2 (49) is too far. Activity 0 is exactly 5 away, which still counts. From closest to farthest: 1 (4), 3 (5), 4 (16), 0 (25), so the answer is [1, 3, 4, 0].
Example 2
home = [0,0]activities = [[3,0],[0,-3],[-2,2],[3,3]]radius = 3return = [2,0,1]Activity 2 at (-2, 2) is about 2.83 away (squared distance 8). Activities 0 and 1 are both exactly 3 away (squared distance 9), so the smaller index, 0, comes first. Activity 3 at (3, 3) is about 4.24 away (squared distance 18), more than 3. The answer is [2, 0, 1].
Example 3
home = [10,10]activities = [[20,10],[10,-5]]radius = 9return = []The activities are 10 and 15 away, both more than 9, so nothing can be suggested and the answer is an empty array.
Constraints
1 <= activities.length <= 2000home.length == 2andactivities[i].length == 2-10^7 <= home[j], activities[i][j] <= 10^70 <= radius <= 3 * 10^7
More Expedia Onsite Interview questions
- Scramble StringONSITE INTERVIEW · Seen Sep 2026
- Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
- Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
- Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
- Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
- Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
- Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
- Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
- Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
- Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024
Similar questions at other companies
- Net Position Calculation from API SnapshotsHeadlands Technologies · ONSITE INTERVIEWHeadlands Technologies interview questions
- Retrieve Vectors by Cosine SimilarityHarvey · ONSITE INTERVIEWHarvey interview questions
- Optimal Central WarehouseGoogle · ONSITE INTERVIEWGoogle interview questions
- Beam Search and Nucleus DecodingMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Pick the K Nearest Grid Points to (0, 0)Capital One · PHONE SCREEN · ONSITE INTERVIEWCapital One interview questions
- Employee Count Median, Mean and ModeClay · PHONE SCREEN
- Maximum Three-Server Difficulty ScoreVisa · OAVisa interview questions
- Maximize Efficiency with TikTokTikTok · OATikTok interview questions
- Adjacent Order-Statistic Gap DistributionsScale AI · PHONE SCREENScale AI interview questions
- Delete and Freeze GameRubrik · OARubrik interview questions
Expedia interview experiences
- Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
- Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
- Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
- Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
- Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)
- Expedia SWE Intern Final Round: 126 Experiences (Part 1 of 6)