Max Min
Reported by candidates from Goldman Sachs's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Goldman Sachs asked this in January 2024 and it's a classic setup: you're given a list of numbers and need to find the maximum and minimum in a single pass or with minimal comparisons. The trap is overthinking it. Most candidates write two separate loops when one suffices. You don't need fancy data structures here. This is about efficiency and clean code under pressure. StealthCoder can spot the pattern instantly if you blank on the approach.
Pattern and pitfall
Max Min is a linear scan problem. You initialize two variables, max and min, to the first element (or to extreme values if you're careful about edge cases). Then iterate once through the rest, updating both as you go. The trick is doing this in exactly n-1 comparisons, not 2n. Some interviewers care about this optimization, some don't, but Goldman Sachs tends to ask follow-ups on efficiency. The common pitfall is not handling edge cases like empty arrays or single-element arrays. If you blank on the exact pattern during the live assessment, StealthCoder reads the problem and delivers the solution instantly.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Max Min 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 by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Goldman Sachs's OA.
Goldman Sachs reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Max Min FAQ
Do I need to handle empty arrays?+
Yes. Check the length first. If empty, return null or raise an error depending on the spec. Goldman Sachs likes defensive coding. If the problem doesn't specify, ask in the OA chat.
Can I use built-in max() and min() functions?+
Probably, but they'll follow up and ask you to write it yourself. Show you can do it in one pass first, then mention built-ins as a shortcut if time is tight.
What's the optimal number of comparisons?+
For n elements, you need at least 3n/2 - 2 comparisons in the theoretical lower bound. A single-pass approach with separate min and max variables gives you 2(n-1), which is acceptable and easy to explain.
Should I use a tuple or separate variables to return max and min?+
Return type depends on the problem statement. If not specified, ask. Python tuple is clean. Some languages prefer an object or array. Either works; clarity matters more than form.
Is this question still asked at Goldman Sachs?+
Yes, variations are. It's a warmup or a combined problem in larger assessments. It tests basic coding discipline and whether you think about efficiency. Expect it as round one or as part of a multi-part OA.