FastPrepFastPrep
Problem Brief

Create Array Generator Service

FULLTIMEOA
See Amazon online assessment and hiring insights

Your development team has been assigned the task of designing a dynamic array generator tool to support software testing workflows. This generator service is designed to create an array that adheres to specific selection and unlocking rules.

The function takes the following parameters:

  • elements[n]: an array of n positive integers.
  • availability: a string of n characters where:
    • Each character is either '0' or '1'.
    • If availability[i] = '1', the corresponding elements[i] is selectable.
    • If availability[i] = '0', the corresponding elements[i] is initially locked.
  • To construct an output array, resultSet, the following process is executed exactly operations times. Initially, resultSet is empty.

  • Choose any available element elements[i], where availability[i] = '1'. Elements can be selected multiple times.
  • Append the chosen value to resultSet.
  • For any availability[i] = '0' where availability[i-1] = '1', update availability[i] to '1'. For instance, if availability was '0100101' before selection, it would become '0110111' after selection.
  • The goal is to generate the lexicographically largest possible sequence resultSet after operations selections.

    Note: A sequence x is considered lexicographically larger than sequence y if there exists an index i (0 ≤ i < operations) where x[i] > y[i], and for any j (0 ≤ j < i), x[j] = y[j].

    1Example 1

    Input
    elements = [10, 5, 7, 6], availability = "0101", operations = 2
    Output
    [6, 7]
    Explanation
    This test case was added on March 1, 2025, for your testing convenience. Relevant information is included in the source image section below.

    Step 1: Initially, only {6} is available since availability[3] = '1'.

    Step 2: Select 6. This unlocks availability[2], making {7} available.

    Step 3: Select 7. We have now performed operations = 2 selections.

    2Example 2

    Input
    elements = [4, 9, 1, 2, 10], availability = "10010", operations = 4
    Output
    [4, 9, 10, 10]
    Explanation
    This test case was added on March 1, 2025, for your testing convenience. Relevant information is included in the source image section below.

    Step 1: Initially available elements: {4, 10}.

    Step 2: Select 4, unlocking availability[1] → {4} → {9}.

    Step 3: Select 9, unlocking availability[2] → {9} → {1}.

    Step 4: Select 10, unlocking availability[3] → {10} → {2}.

    Step 5: Select 10 again.

    3Example 3

    Input
    arr = [5, 3, 4, 6], state = "1100", m = 5
    Output
    [5, 5, 6, 6, 6]
    Explanation
    N/A 🥲 If you happen to know about it, pls feel free to lmk! Manyyy thanks in acvance! 😘
    public int[] generateOptimalSequence(int[] elements, String availability, int operations) {
      // write your code here
    }
    
    Input

    elements

    [10, 5, 7, 6]

    availability

    "0101"

    operations

    2

    Output

    [6, 7]

    Sign in to submit your solution.

    Company OA Practice

    Create Array Generator Service for Amazon online assessment prep

    FastPrep catalogs Create Array Generator Service as a Amazon coding interview and online assessment practice problem. Review the prompt, examples, constraints, and nearby company problems together so the preparation context stays focused on Amazon OA patterns.