← 2023 questions

2023 / SHOPEE / QUESTION 34

Delivery order

Try the question in your own editor, then check your output below.

THE QUESTION

Valerie has ordered a few items off a shopee bakery. She wants the orders to arrive in the order they are completed. The bakery has informed her that the lesser orders will be completed quicker and thus also delivered sooner. Valerie wants to know which items will arrive first.

Here is the quantity of each of her purchases:

list = [4, 9, 2, 1, 2, 6, 3]

Use the bubble sort algorithm to sort the array so that it displays the least amount of purchases to the largest amount (from left to right)

Question by Elena. Source: Girls In Code SEA — Behind the Screens, 2023, slide 54.

CHECK YOUR ANSWER

Try your answer.

Run your program in your own editor, then paste its output below. This checks the stated output; it does not assess your full program. Practice attempts do not affect competition scores.

Enter the sorted values as a list or separated by spaces.

Reveal worked answer

Sorted purchases

[1, 2, 2, 3, 4, 6, 9]

Swap adjacent out-of-order values until sorted. Retain both occurrences of 2.