Tap here to switch tabs
Problem
Submissions

Problem: Previous Permutation With One Swap

med
30 min
Try to solve the Previous Permutation With One Swap problem.

Statement

Given an array of positive integers arr, return the lexicographically largest permutation that is smaller than arr and can be formed by swapping two elements at distinct indices exactly once. If no such permutation exists, return arr unchanged.

Constraints:

  • 1≤1 \leq arr.length ≤104\leq 10^4

  • 1≤1 \leq arr[i] ≤104\leq 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Previous Permutation With One Swap

med
30 min
Try to solve the Previous Permutation With One Swap problem.

Statement

Given an array of positive integers arr, return the lexicographically largest permutation that is smaller than arr and can be formed by swapping two elements at distinct indices exactly once. If no such permutation exists, return arr unchanged.

Constraints:

  • 1≤1 \leq arr.length ≤104\leq 10^4

  • 1≤1 \leq arr[i] ≤104\leq 10^4