Reported December 2024
Microsoftmath

Max Sum With Same First And Last Digit

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

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

Microsoft's December OA included a math problem asking you to find the maximum sum of elements that share the same first and last digit. You're not looking for a complex algorithm here. The real challenge is parsing the constraint correctly and grouping numbers by their digit signature. If you blank on the grouping logic during the live assessment, StealthCoder will read the problem and feed you the pattern instantly. The math label is a hint: you're summing, not sorting or searching.

Pattern and pitfall

The trick is recognizing that you need to group numbers by a shared property, then pick the group with the highest sum. First, extract the first and last digit of each number. For single-digit numbers, first and last are the same. Group all numbers where first digit equals last digit into buckets keyed by that digit pair. Then return the maximum sum across all buckets, or zero if no valid group exists. The common pitfall is overthinking the 'same' constraint or trying to track indices when you only need sums. This is pure grouping and aggregation. If you get stuck during the OA, StealthCoder can surface the grouping pattern and walk you through the implementation without the proctor seeing.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Max Sum With Same First And Last Digit 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. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as group anagrams. If you have time before the OA, drill that.

⏵ The honest play

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

Microsoft reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Max Sum With Same First And Last Digit FAQ

What does 'same first and last digit' mean for a number like 121?+

First digit is 1, last digit is 1. They match, so 121 belongs in the group for digit pair (1,1). A number like 123 has first 1, last 3, so it doesn't qualify for any same-digit group.

Is this asking for a subsequence, or just a sum of all valid numbers?+

Sum all numbers in the group with the highest sum. You're not picking a subsequence or reordering. Filter the array, group by first-last digit match, sum each group, return the max.

How do I extract first and last digit from a number?+

Convert to string and take index 0 and index -1. Or use modulo and division: last digit is n % 10, first digit is found by repeatedly dividing by 10 until you have one digit left.

What if no numbers have matching first and last digits?+

Return 0. The maximum sum of an empty set is 0. Don't throw an error or return null unless the problem specifies otherwise.

Is this problem still asked at Microsoft, or is this old?+

This was reported in December 2024. Math and grouping problems are evergreen in OAs. The exact wording changes, but the pattern of 'group by property, find max sum' appears regularly.

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

OA at Microsoft?
Invisible during screen share
Get it