Tap here to switch tabs
Problem
Submissions

Problem: Lexicographically Smallest Array by Swapping Elements

Try to solve the Make Lexicographically Smallest Array by Swapping Elements problem.

Statement

You are given a 00 indexed array of positive integers nums and a positive integer limit.

In a single operation, you can swap the elements at any two indices i and j if ∣|nums[i] −- nums[j]∣≤| \leq limit.

Return the lexicographically smallest array that can be obtained by performing this operation any number of times.

Note: An array a is lexicographically smaller than an array b if in the first position where a and b differ, array a has an element that is strictly smaller than the corresponding element in b.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • 1≤1 \leq limit ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Lexicographically Smallest Array by Swapping Elements

Try to solve the Make Lexicographically Smallest Array by Swapping Elements problem.

Statement

You are given a 00 indexed array of positive integers nums and a positive integer limit.

In a single operation, you can swap the elements at any two indices i and j if ∣|nums[i] −- nums[j]∣≤| \leq limit.

Return the lexicographically smallest array that can be obtained by performing this operation any number of times.

Note: An array a is lexicographically smaller than an array b if in the first position where a and b differ, array a has an element that is strictly smaller than the corresponding element in b.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • 1≤1 \leq limit ≤109\leq 10^9