Lexicographically Maximum Final Sequence
Learn this problemProblem statement
You are given a binary string shipmentData consisting only of '0' and '1'.
A final string is built from a chosen ordering of shipmentData as follows:
- Start with an empty string
finalSequence. - For each character
cin the chosen ordering from left to right, appendctofinalSequence, then reversefinalSequence.
You may rearrange the characters of shipmentData arbitrarily before applying the operation. Return the rearranged shipmentData string that should be fed into the operation to produce the lexicographically maximum possible finalSequence.
Do not return finalSequence itself. The answer must be a rearrangement of the original shipmentData.
Function
rearrangeShipmentData(shipmentData: String) → StringExamples
Example 1
shipmentData = "0011"return = "0101"The returned rearranged string is "0101". If this string is fed into the operation, the resulting final sequence is "1100", which is lexicographically maximum among all rearrangements.
Example 2
shipmentData = "10100"return = "00101"The final sequence reads positions 5,3,1,2,4 from the rearranged string. Placing the two '1' characters at positions 5 and 3 produces final sequence "11000".
Constraints
shipmentData.length >= 1shipmentDatacontains only'0'and'1'.
More Amazon problems
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Sort Bug Report FrequenciesOA · Seen Jul 2026
- Drone Delivery RouteOA · Seen Jul 2026