FastPrepHiking Club Fastest Pace
Problems/Hiking Club Fastest Pace

Hiking Club Fastest Pace

Infosys logoInfosys● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported from an Infosys online assessment for the Specialist Programmer and Digital Specialist Engineer roles in November 2026. Hikers sign up alone or as pairs who stay together, the guide needs a minimum number of hikers, the hike goes at its slowest member's pace, and you return the fastest pace possible.

The report gave this task, the input layout (the number of groups, one row per group with a 0 for a solo hiker, then the minimum) and three examples with answers. It gave no limits. The person who reported it was not sure whether the minimum counts hikers or groups. We count hikers, as the task itself says, so a pair counts as two. We chose the limits (up to 10^4 groups, paces up to 10^9, a minimum of up to 2 * 10^4), and the groups and the minimum are passed to a function instead of being read line by line.

Our version is about 90% the same as the reported question.

A hiking club takes sign-ups in groups. Each group is given as groups[i] = [pace1, pace2]:

  • If pace2 > 0, the group is two friends who insist on hiking together. Their paces are pace1 and pace2.
  • If pace2 == 0, the group is one hiker who hikes alone, with pace pace1.

A larger pace means a faster hiker. The guide takes whole groups only, so the two friends of a pair are taken together or not at all. The guide needs at least m hikers, and the hike moves at the pace of its slowest hiker.

Choose the groups so that the hike is as fast as possible, and return that pace. If fewer than m hikers signed up in total, return -1.

Function

fastestHikePace(groups: int[][], m: int) → int

Examples

Example 1

groups = [[5,0]]m = 1return = 5

The only group is one hiker with pace 5. Taking that group gives 1 hiker, which is enough, so the hike moves at pace 5.

Example 2

groups = [[6,4],[5,0]]m = 2return = 4

The pair moves at pace 4, the slower of 6 and 4. The solo hiker with pace 5 is only 1 hiker, which is not enough on its own. Taking the pair gives 2 hikers at pace 4, and taking both groups gives 3 hikers, still at pace 4. So the answer is 4.

Example 3

groups = [[9,2],[7,0],[6,0]]m = 2return = 6

Take the two solo hikers with paces 7 and 6. That is 2 hikers, and the hike moves at pace 6. Any choice that includes the pair also brings its slower member with pace 2, so that hike would move at pace 2. Taking only the hikers with paces 9 and 7 would give pace 7, but that splits the pair, which is not allowed. So the answer is 6.

Constraints

  • 1 <= groups.length <= 10^4
  • groups[i].length == 2
  • 0 <= groups[i][j] <= 10^9
  • groups[i][0] >= 1
  • 1 <= m <= 2 * 10^4

More Infosys Online Assessment questions

  • Lowest Common Ancestor with a Changing RootOA · Seen Nov 2026
  • Minimum Leaf Path Sum over All RootsOA · Seen Nov 2026
  • Split Array to Minimize the Largest SumOA · Seen Nov 2026
  • Cherry PickupOA · Seen Nov 2026
  • Lexicographically Smallest Grid Path with One Letter ChangeOA · Seen Nov 2026
  • Minimum Cost to Supply Water with Wells and PipesOA · Seen Nov 2026
  • Minimum Cost to Tile a Strip with Widths 1, 2, and 3OA · Seen Nov 2026
  • Minimum Rounds to Complete All TasksOA · Seen Nov 2026
  • Lift Total TravelOA · Seen Nov 2026
  • Count Equal-Distinct Character PartitionsOA · Seen Oct 2026

Similar questions at other companies

  • Find Minimum TimeAlphaSense · OA
  • Find Minimum TimeBlackRock · OA
  • Maximum Easy Tasks After RearrangingIBM · OA
  • Minimum Cost K-Capable ModelsMicrosoft · OA
  • Minimum Cost of Every K-Capable Model SetTikTok · OA
  • Maximum Distinct Values After Unit AdjustmentsBirla Pivot · OA
  • Maximize Revenue from Decreasing InventoryChubb · OA
  • Minimum Distinct Prefix CostGoldman Sachs · OA
  • Maximize Minimum Deployment DifficultyJP Morgan Chase · OA
  • Latest Arrival to Catch a BusAutodesk · OA
See Infosys hiring insights
Saved
class Solution {
    public int fastestHikePace(int[][] groups, int m) {
        // Write your code here.
    }
}
Checking account…