Max Lucky Numbers
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Amazon asked this in April 2024, and it's a trap if you overthink it. You're looking for 'lucky numbers' in a matrix, and the problem sounds like a hard search or dynamic-programming grind. It's not. The trick is understanding what 'lucky' actually means in the context of the problem statement, then realizing you can solve it with a single pass through the data. Most candidates fail because they build the wrong mental model first. StealthCoder reads the exact wording and spots the pattern before you waste 10 minutes on false starts.
Pattern and pitfall
A lucky number is typically defined as a number that's the minimum in its row AND the maximum in its column (or vice versa, depending on the problem wording). The key insight is that you don't need nested loops or recursion. Precompute the minimum of each row and the maximum of each column in two passes, then iterate through the matrix once more and check each cell against both precomputed arrays. Time complexity is O(m*n) and space is O(m+n). The common pitfall is building a hash table of lucky numbers or trying to validate candidacy on the fly with nested checks, which bloats your code and invites off-by-one errors. The real pattern here is prefix/aggregation: compute row minimums and column maximums upfront, then filter.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Max Lucky Numbers 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 StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as lucky numbers in a matrix. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon 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.
Max Lucky Numbers FAQ
What if there are no lucky numbers?+
Return an empty list. The problem will specify the output format, but it's always valid to return nothing. Don't overthink edge cases; code them as stated in the problem and move on.
Can a number be lucky if it's in multiple cells?+
Yes, but each cell is checked independently. If the value 5 appears in multiple cells and each one qualifies, all instances count. The problem usually asks for the list of lucky numbers, not unique values, so duplicates matter.
Is this really an easy problem?+
Yes. Amazon uses it to filter for people who panic or over-engineer. If you see matrix and 'lucky', don't assume dynamic programming. Read the definition, code the two-pass approach, and move on in under 5 minutes.
What languages does this support?+
The OA will support Python, Java, C++, and JavaScript at minimum. Pick what you're fastest in. The logic is the same across all languages; only the syntax for row/column iteration and array construction changes.
Should I validate input size or edge cases?+
Only if the problem explicitly asks. Assume the input is non-null and within bounds. Write clean code that solves the happy path first, then add guards only if you have time and the problem statement suggests it.