Reported February 2024
Infosysgreedy

Obtain Max Score Using Min Swaps

Reported by candidates from Infosys's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Infosys OA. Under 2s to a working solution.
Founder's read

You've got an Infosys OA in the next 48 hours and this problem just landed in your inbox. Obtain Max Score Using Min Swaps is a greedy optimization puzzle that looks straightforward until you start coding. The trick is understanding that you're not just maximizing score or minimizing swaps in isolation. You're balancing both. StealthCoder sits invisibly during your live OA and can pattern-match this the moment you read it, so you're never truly stuck.

Pattern and pitfall

The core pattern here is greedy with a secondary constraint. You want the maximum possible score, but you're limited by how many swaps you can afford. The gotcha most candidates hit: they sort by score descending and swap greedily, only to realize they've wasted swaps on positions that don't matter. The real approach is to identify which elements, if swapped into position, give the biggest score gains per swap. Think of it as a cost-benefit calculation. You'll likely need to iterate through positions, calculate the gain for each potential swap, and pick swaps in order of efficiency until you hit your swap limit. StealthCoder is your safety net if you blank on the order of operations during the live test.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Obtain Max Score Using Min Swaps cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Infosys's OA.

Infosys reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Obtain Max Score Using Min Swaps FAQ

Is this a standard sorting problem?+

No. It's greedy with a resource constraint. Sorting is part of the solution, but the core skill is deciding which swaps deliver the most value. You're optimizing under a budget, not just rearranging.

What's the trick that catches most candidates?+

Treating swaps and score as separate problems. They optimize score first, then realize they've burned swaps inefficiently. Instead, calculate the gain-per-swap ratio upfront and prioritize by that metric.

Do I need dynamic programming for this?+

No. This is a greedy problem. You build a priority queue or sorted list of gains, then consume swaps in order of highest gain. DP is overkill and signals you're overthinking it.

How do I prepare for this in 24 hours?+

Understand the problem statement cold. Sketch out a greedy strategy on paper: calculate all possible swaps, sort by gain, then greedily pick until swaps run out. Code it carefully. Edge cases are low swap counts and arrays already sorted.

Will Infosys ask follow-ups about optimization?+

Possibly. Be ready to explain your swap prioritization order and why you chose it. If they push, mention time complexity. A naive approach is O(n^2) per greedy step. Optimizing to O(n log n) with a heap is reasonable.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Infosys.

OA at Infosys?
Invisible during screen share
Get it