Nutanix Sports Meet
Updated
Problem statement
It is sports day at Nutanix. The runners, called nutants, race along a one-lane road to a finish line that is m miles from the start of the road.
Runner i starts position[i] miles along the road and runs toward the finish at its top speed of speed[i] miles per hour. Nobody can pass the runner in front. When a runner catches up with the runner or group ahead, it stays right behind them, and from then on they all move together at the speed of the group in front.
A nugang is a group of one or more runners at the same position moving at the same speed. A runner on its own is also a nugang. A runner that catches up with a group exactly at the finish line finishes as part of that group.
Return the number of nugangs that reach the finish line.
Function
countNugangs(m: int, position: int[], speed: int[]) → intExamples
Example 1
m = 12position = [10,8,0,5,3]speed = [2,4,1,1,3]return = 3The runners at miles 10 and 8 both need 1 hour to finish, so the runner from mile 8 reaches the runner from mile 10 right at mile 12. They finish as one nugang.
The runner from mile 3 is faster than the runner at mile 5. After 1 hour both are at mile 6, so they move on together at speed 1 and finish at hour 7.
The runner from mile 0 also has speed 1. It needs 12 hours and never catches anyone, so it finishes alone.
That makes 3 nugangs.
Example 2
m = 20position = [0,6,10]speed = [3,3,1]return = 1The runner from mile 6 catches the runner at mile 10 after 2 hours, at mile 12. From then on that group moves at speed 1.
The runner from mile 0 has the same speed as the runner from mile 6, so it could never catch that runner alone. But after 2 hours it is at mile 6, 6 miles behind the slowed group, and it gains 2 miles per hour. It joins the group 3 hours later, at mile 15.
Everyone finishes together, so the answer is 1.
Example 3
m = 7position = []speed = []return = 0No runners take part, so no nugang reaches the destination.
Constraints
n == position.length == speed.length0 <= n <= 5 * 10^40 < m <= 10^60 < speed[i] <= 10^60 <= position[i] < m- All values in
positionare different.
More Nutanix Online Assessment questions
- Good SubsequencesOA · Seen Jul 2026
- Min Cost to Connect All PointsOA · Seen Jun 2026
- Digit Changes for a Multiple of 9OA · Seen Aug 2025
- Gas Station Loop StartOA · Seen Aug 2025
- Number of Players (for MTS2)OA · Seen Oct 2024
- Work Schedules (for MTS2)OA · Seen Oct 2024
- Minimum Operations to Convert ArrayOA · Seen Apr 2024
- No Adjacent CharactersOA · Seen Apr 2024
- Build a BST From a ListOA · Seen Nov 2022
- Delete Even-Valued Nodes From a Linked ListOA · Seen Nov 2022
Similar questions at other companies
- Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
- Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
- Maximum Distinct Values After Unit AdjustmentsBirla Pivot · OA
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
- Maximize Minimum Deployment DifficultyJP Morgan Chase · OAJP Morgan Chase interview questions
- Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
- Maximize Center A Package BenefitAmazon · OA
- EV Charging Cost OptimizationTata Consultancy Services · OATata Consultancy Services interview questions
- Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions