Reported August 2024
IBMsorting

Get Min Difference

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

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

IBM asked this in August 2024, and it's a classic array problem that looks simple until you realize you need to sort first. You've got a list of numbers, and you need to find the smallest difference between any two elements. Most candidates jump straight into nested loops and miss the key insight: once sorted, the minimum difference always lies between adjacent elements. StealthCoder can spot this pattern in seconds if you blank on the approach.

Pattern and pitfall

The trick is recognizing that after sorting, you only need to compare consecutive pairs. An unsorted array hides the minimum difference across scattered indices, but a sorted one exposes it immediately. Iterate through the sorted array once, tracking the minimum gap between arr[i] and arr[i+1]. Time complexity drops from O(n^2) brute force to O(n log n) with sorting. Edge cases: empty arrays, single element, duplicates (difference of zero). If you get stuck mid-OA, StealthCoder handles the sorting logic and the iteration pattern so you don't tank the solution.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Get Min Difference 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 StealthCoder

Related leaked OAs

⏵ The honest play

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

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

Get Min Difference FAQ

Do I really need to sort?+

Yes. Sorting is the entire trick. Without it, you'd check every pair, which is O(n^2) and way too slow. Sorting guarantees the minimum difference is between adjacent elements in the sorted order.

What if the array has duplicates?+

Duplicates have a difference of zero, which is the minimum possible. Your loop catches this immediately. The algorithm still works; you just return 0 early if you encounter identical adjacent elements.

Is this still being asked at IBM?+

It was asked in August 2024. Array sorting problems are IBM staples. This specific one tests whether you know the optimization trick, so it's likely still in rotation.

How do I solve this in under 10 minutes?+

Sort the array (one line in most languages), then loop through once tracking the minimum difference between consecutive pairs. Write the loop cleanly and test with a small example. That's it.

What languages is this asked in?+

IBM typically supports Java, Python, C++, and C. The algorithm is identical across all of them; only syntax differs. Pick whichever you're fastest in.

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

OA at IBM?
Invisible during screen share
Get it