Problem 26 of 50

Easy

lightbulb What to do

You have a list of five numbers that are mixed up. You need to check if you can sort them in order by swapping just two numbers that are next to each other. If you can do it, say 'Yes'; if not, say 'No'.

Key Concepts
if-statements arrays/lists swapping elements basic comparison
Examples

Input: [1, 2, 4, 3, 5]

Output: Yes

Input: [5, 3, 2, 4, 1]

Output: No

code Python Editor
Loading Python...
Test Results
tips_and_updates Tips for Beginners
  • Focus on understanding the logic, not memorizing syntax
  • Use print statements to debug your code
  • Don't worry about input parsing - the function handles that for you
  • If stuck, try writing out your solution on paper first