Problem · String
Lexicographically Smallest Task Queue
A system manages a queue of tasks represented by a string taskQueue. Each character is one of:
'1': low priority'2': medium priority'3': high priority
You may perform either of the following adjacent swaps any number of times:
- swap adjacent tasks with values
'1'and'2' - swap adjacent tasks with values
'2'and'3'
Return the lexicographically smallest task order that can be obtained.
A task order a is lexicographically smaller than task order b if, at the first position where they differ, a has the smaller priority character.
Examples
01 · Example 1
taskQueue = "13212" return = "12231"
The two '2' tasks can move before the first '3', but the relative order of the '1' and '3' tasks cannot be changed directly. The smallest reachable order is "12231".
Constraints
1 <= taskQueue.lengthtaskQueuecontains only'1','2', and'3'.
More Agoda problems
- Minimum Absolute Difference PairsONSITE INTERVIEW · Seen Jun 2026
- Count One Groups by SizeOA · Seen Jul 2025
- Minimum Price With Discount CouponsOA · Seen Jul 2025
- Team FormationSeen Apr 2025
- Two-Core Process AssignmentSeen Apr 2025
- Unique Digits in RangeSeen Apr 2025
- Maximize Sum of Processed TimesSeen Sep 2024
public String getSmallestTaskQueue(String taskQueue) {
// write your code here
}taskQueue"13212"
expected"12231"
sign in to submit