InterviewLegend

Sorting, Greedy & Binary Search

Alex Chen38 min readUpdated 328 real interview reports

IBM prompts rarely say "sort," but sorting is behind a fair share of the assessment. One prompt might ask for the largest team whose skill levels are close together. Another might want a day of transactions ordered so the balance stays positive for as long as possible. In both, sorting first turns a question about every possible subset or ordering into one pass over a sorted list. Intervals, sorting and greedy choices together are roughly an eighth of IBM's coding, on the same HackerRank test as the arrays.

Two of the problems are about the sort itself. One needs a key whose tiebreak runs the other way, and one sorts pieces of a string while the boundaries between those pieces stay put. Two more use sorting as setup, one with a run counter and one with a greedy running total. The last is a binary search with no target value, where the sorted order the prompt gives you is the only hint.

The IBM angle
IBM's hidden tests check ties. Each of these problems has a version that sorts on the obvious key and passes the samples. Then a hidden case has two values with the same frequency, or a running total that reaches zero without going below it, and the obvious key gives the wrong answer. Before you call sort, decide what should happen when two elements compare equal, and build that rule into the key.

IBMPremium lesson · Coding round

The 5 IBM problems are below.

  1. A Premium questionCoding · Easy · Frequently asked
  2. A Premium questionCoding · Medium
  3. A Premium questionCoding · Medium

+ 2 more in this lesson

Each with hints, the follow-up and a tested solution.

Get the IBM questions

$49 a year · all 100 companies · cancel anytime

From 328 IBM reports, forum threads behind logins and write-ups in Chinese.

Had your IBM interview?Tell us what they asked. Reviewed before it goes in, never with your name.
IBM interview guide

Know what IBM asks before you walk in.

30 coding · 3 system design · 13 behavioral questions

Get Premium$49 a year · Cancel anytime
Or start freeNo card.

Get their questions first.

InterviewLegend is independent and not affiliated with or endorsed by any company it covers.