Maximum Number With Single Swap
You are given an array of N elements that represent the digits of a number. You can perform one swap operation to exchange the values at any two indices. Your task is to determine the maximum possible number that can be achieved by performing at most one swap.
Example:
Input:
array = [1,3,2,7]
Output:
[7,3,2,1]
Explanation:
The input array represents the number 1327. After exploring possible swaps, swapping indices 1 and 4 yields the maximum number 7321. Thus, the output array is [7, 3, 2, 1].
Constraints:
1 <= T <= 100
2 <= N <= 104
0 <= A[i] <= 9
- The array can include leading zeros.
Note:
For each test case, the output should be printed where elements are space-separated, on a new line for each test case.


Given an array of digits, find the maximum number that can be achieved by performing at most one swap.
Iterate through the array to find the maximum digit.
If the maximum digit is already at the beginni...read more

Top Walmart SDE-2 interview questions & answers
Popular interview questions of SDE-2
Reviews
Interviews
Salaries
Users/Month