Tap here to switch tabs
Problem
Submissions

Problem: Previous Permutation With One Swap

Previous Permutation With One Swap asks for the lexicographically largest permutation smaller than the input array after exactly one swap of two distinct positions, or unchanged if impossible.

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

Previous Permutation With One Swap asks for the lexicographically largest permutation smaller than the input array after exactly one swap of two distinct positions, or unchanged if impossible.

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