12435
ABC 390Problem 26 of 50
EasyWhat to do
Given a list of 5 integers (a permutation of 1-5), check if you can sort it in ascending order by swapping exactly one pair of adjacent elements. Return 'Yes' if exactly one adjacent swap produces [1,2,3,4,5], 'No' otherwise.
Key Concepts
if-statements
arrays/lists
swapping elements
basic comparison
Examples
Input:
arr = [1, 2, 4, 3, 5]
Output:
Yes
Input:
arr = [5, 3, 2, 4, 1]
Output:
No
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
Python Editor
Loading Python...