Find Maximum Possible GCD
Reported by candidates from Barclays's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Barclays asked this in March 2024, and it's a clean math problem hiding a brute-force trap. You're looking for the maximum possible GCD of some subset or result derived from an array. The instinct is to iterate and check, but the real pattern is recognizing that the answer is bounded by the input values themselves, and you only need to test divisors. StealthCoder sits ready if the divisor-based iteration doesn't click under pressure.
Pattern and pitfall
The trick here is that the maximum GCD you can achieve is capped by the largest element in the array. You don't search all integers; you only test divisors of the numbers you're given. The algorithm is: iterate from the largest possible GCD downward, and for each candidate, check if it divides the required elements (or satisfies the problem constraint). Most candidates waste time on a brute-force O(n^2) or O(n log n) approach when a divisor-enumeration method cuts it to O(d(max) * n), where d is the divisor count. StealthCoder will flag this pattern instantly if you blank on optimization.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Find Maximum Possible GCD 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 passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Barclays's OA.
Barclays reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Find Maximum Possible GCD FAQ
Is this a standard GCD problem or something tricky?+
It's math, not a number-theory theorem. The problem is asking you to find the maximum divisor that satisfies some constraint over the array. Think divisor iteration, not Euclidean algorithm loops. Test candidates from high to low.
Do I need to compute GCD of pairs or the whole array?+
The problem statement isn't provided, so it depends on the exact wording. However, the pattern is the same: enumerate candidate GCDs (divisors of your input) and validate each one. The constraint will tell you what 'valid' means.
What's the common mistake candidates make?+
Trying to iterate through every integer up to the max element and check if it's a valid GCD. That's too slow. Instead, only test divisors of the numbers in the array. Use a factor-finding loop or prime factorization to speed it up.
How do I prep this in 48 hours?+
Understand divisor enumeration: write a function that returns all divisors of a number in O(sqrt(n)) time. Then practice testing divisors in descending order. One LeetCode GCD problem should be enough; this is pattern recognition, not deep theory.
Is this harder than typical Barclays OA math problems?+
No. It's straightforward once you spot the divisor pattern. The difficulty is the first instinct to brute-force. If you recognize the constraint is 'find max divisor where condition X holds,' you're 90% done.