Maximum Alternating-Index Packet Value
Updated
Problem statement
You are given nonnegative packet values and an integer budget. Select exactly budget packets. The selected packets must alternate between original 0-based even and odd indices; the first selected packet may come from either parity.
The selected values may be arranged in any order that satisfies the parity alternation. Return the maximum possible total value.
Function
maximumAlternatingPacketValue(packetValues: int[], budget: int) → longExamples
Example 1
packetValues = [8,1,7,5,4,9]budget = 4return = 29Choose even-index values 8 and 7 plus odd-index values 9 and 5.
Example 2
packetValues = [8,1,7,5,4,9]budget = 5return = 33Starting with an even index permits three even-index and two odd-index packets.
Constraints
1 <= packetValues.length <= 2000000 <= packetValues[i] <= 10^91 <= budget <= packetValues.length
Source note: Interview prompt excerpt preserved as source evidence.
More Infosys Online Assessment questions
- At Most K Jumps with Quadratic Transition CostOA · Seen Nov 2026
- Hiking Club Fastest PaceOA · Seen Nov 2026
- 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
Similar questions at other companies
- Find Minimum TimeAlphaSense · OA
- Find Minimum TimeBlackRock · OABlackRock interview questions
- Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
- Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
- Minimum Cost of Every K-Capable Model SetTikTok · OATikTok 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