Reported July 2026
MulticoreWarearray

Second Distinct Largest Element

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

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

The statement says repeated occurrences of the largest value don't count as a separate value, and that one line is the whole question. MulticoreWare reported this OA in July 2026. It's a short array problem: return the second-largest distinct value from nums, which is guaranteed to hold at least two distinct values. Easy on paper, but the duplicate rule trips people who rush. If you've got the invite and 48 hours, this is a pattern you can lock in fast. StealthCoder sits invisibly on your screen as a safety net if your mind goes blank mid-assessment, but the logic below should be enough.

The problem

Given an integer array nums containing at least two distinct values, return its second-largest distinct value.
Repeated occurrences of the largest value do not count as a separate value.

Function
secondLargestDistinct(nums: int[]) → int

Examples
Example 1
nums = [5,1,5,3]
return = 3
Example 2
nums = [2,2,1]
return = 1

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is one pass with two trackers: largest and second. For each number, if it's greater than largest, shift largest into second and update largest. Else if it's less than largest and greater than second, update second. The strict comparisons are what handle duplicates. In [5,1,5,3], the second 5 equals largest, so it's ignored, and you end at 3. The common pitfall is sorting and grabbing index n-2, which returns 5 on that example and fails. Another is initializing second to 0 when negatives are allowed. Use negative infinity, or a null flag. The guarantee of two distinct values means second will always get set. A set plus sort works too, but the single pass is O(n) time and O(1) space. If you freeze during the live OA, StealthCoder can hand you this tracker logic in real time without the proctor seeing it.

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 Second Distinct Largest Element 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

⏵ The honest play

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

MulticoreWare 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.

Second Distinct Largest Element FAQ

How hard is the second distinct largest element problem really?+

It's easy. The only real difficulty is the duplicate rule. Candidates who sort and pick the second-to-last element fail the [5,1,5,3] example. If you handle equality correctly, this takes about five minutes to write and test.

What's the trick for this MulticoreWare OA question?+

Track the largest and second-largest in one pass using strict comparisons. Update second only when a value is less than largest and greater than second. That skips repeated copies of the max automatically, so you never need extra data structures.

Can I just use a set and sort?+

Yes. Convert nums to a set, sort it, and return the second-to-last value. It's O(n log n) and perfectly correct. The single pass is faster and shows cleaner thinking, but the set approach is a safe fallback if you're short on time.

What edge cases should I test before submitting?+

Test negatives like [-1,-5,-1], where a zero initializer breaks. Test all-duplicates-of-max with one smaller value, like [2,2,1]. Test the smaller value appearing first, then the max repeating. Also test a two-element array with distinct values.

How do I prepare for this in 48 hours?+

Write the two-tracker loop from memory three times, using negative infinity as the starting value. Then do the set-and-sort version as a backup. Run both on the two given examples plus a negative-number case. That's enough for this problem.

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

OA at MulticoreWare?
Invisible during screen share
Get it