Skip to content
Back to libraryPart 1 · Foundations

1.5Sorting

Before you start

It helps to have read 1.3 Arrays and strings and 1.4 Counting and frequency. Overall level: Foundation.

Practice: Sorting

0 of 4 solved

About these problems

Apply, Connect, Reason and Stretch describe difficulty within this topic, not an official contest rating. Open any problem in any order; reading the chapter first is optional.

  1. 1Ordered readingsYou are given a list of n integers a1, a2, ..., an. Print the values in nondecreasing order, from smallest to largest, keeping every copy of repeated values.ApplyNot started
  2. 2Results orderThere are n participants. Each has a distinct integer id and a score. Print the ids ordered by decreasing score; participants with equal scores are ordered by increasing id.ConnectNot started
  3. 3Closest readingsYou are given a list of n integers a1, a2, ..., an. Find the smallest value of |ai - aj| over all pairs of different positions i ≠ j.ReasonNot started
  4. 4Compact coordinatesYou are given a list of n integers a1, a2, ..., an. Replace every value by its rank among the distinct values of the list in increasing order: the smallest distinct value has rank 1, the next has rank 2, and so on. Equal values receive equal ranks. Print the ranks in the original input order.StretchNot started

Read the lesson