FastPrepLexicographically Maximum Final Sequence
Problems/Lexicographically Maximum Final Sequence

Lexicographically Maximum Final Sequence

Amazon logoAmazonFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given a binary string shipmentData. It contains only '0' and '1'.

First, rearrange the characters of shipmentData in any order you like. Then build a string finalSequence from your rearranged shipmentData like this:

  1. Start with an empty finalSequence.
  2. Go through your rearranged string from left to right. For each character c, add c to the end of finalSequence, then reverse finalSequence.

Your goal is the lexicographically maximum finalSequence. That is the one that would come last in dictionary order: compare two results from the left, and at the first place they differ, the one with the larger character is bigger. Return the rearranged shipmentData string that produces it.

Do not return finalSequence itself. Your answer must be a rearrangement of the original shipmentData: the same characters, possibly in a different order.

Function

rearrangeShipmentData(shipmentData: String) → String

Examples

Example 1

shipmentData = "0011"return = "0101"

The rearranged string "0101" builds the final sequence "1100", with both ones at the front. No other rearrangement builds a larger final sequence, so this string is the answer.

Example 2

shipmentData = "10100"return = "00101"

After all the steps, the final sequence lists the characters of the rearranged string from positions 5,3,1,2,4, in that order. To make it as large as possible, put the two '1' characters at positions 5 and 3. The final sequence is then "11000", and the rearranged string with ones at those positions is the answer.

Constraints

  • shipmentData.length >= 1
  • shipmentData contains only '0' and '1'.

More Amazon Online Assessment questions

  • Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent ElementsOA · PHONE SCREEN · Seen Nov 2026
  • Get Smallest Base SegmentOA · Seen Nov 2026
  • Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
  • Minimum Grid InconvenienceOA · Seen Nov 2026
  • Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
  • Maximum Equal-Bit Pairs in a SubsequenceOA · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Two SumOA · PHONE SCREEN · Seen Nov 2026

Interview reports that mention this question

  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
Saved
class Solution {
    public String rearrangeShipmentData(String shipmentData) {
      // write your code here
    }
}
Checking account…