Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Sort Three Numbers Using Conditional Statements

Basic Acceptance 93.23% Points 10.00

You are given three integers. Your task is to return them in ascending order, from the smallest to the largest, using only conditional statements.

You must arrange the numbers without using any built-in sorting function. The numbers may contain duplicates, so equal values must also appear in the correct order.

Examples
Example 1

Input: a = 3, b = 1, c = 2
Output: 1 2 3
Explanation: The values are arranged from smallest to largest.

Example 2

Input: a = 5, b = 5, c = 2
Output: 2 5 5
Explanation: The duplicate values are placed adjacently in ascending order.

Example 3

Input: a = 9, b = 7, c = 8
Output: 7 8 9
Explanation: The three numbers are rearranged into ascending order.

Constraints
  • -10? = a, b, c = 10?
Companies
Amazon Microsoft Apple
Topics
Data Structures Basics Sorting Algorithms Sorting Algorithm + 2 more
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions