PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Amazon

Build the Largest Available Sequence

Last updated: May 7, 2026

Quick Overview

This question evaluates algorithmic problem-solving skills in state simulation, constrained selection, and lexicographic sequence maximization, measuring the ability to reason about evolving availability when constructing sequences.

  • medium
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Build the Largest Available Sequence

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

You are given an integer array `values`, a binary string `state` of the same length, and an integer `m` such that `0 <= m <= values.length`. Build a sequence `s` of length `m` using exactly `m` operations. You may assume it is always possible to complete all `m` picks. In each operation: 1. Choose any index `i` such that `state[i] = '1'`. 2. Append `values[i]` to `s`. 3. Mark that index as unavailable by setting `state[i] = '0'`. 4. Then perform one simultaneous availability update on this new state: for every index `j > 0`, if `state[j - 1] = '1'` and `state[j] = '0'`, flip `state[j]` to `1`. Return the lexicographically largest possible sequence `s`. For integer sequences, lexicographic order compares elements from left to right. Example: - `values = [10, 5, 7, 6]` - `state = "0101"` - `m = 2` One optimal answer is `[6, 7]`. Write a function to compute the lexicographically largest sequence.

Quick Answer: This question evaluates algorithmic problem-solving skills in state simulation, constrained selection, and lexicographic sequence maximization, measuring the ability to reason about evolving availability when constructing sequences.

Related Interview Questions

  • Minimum Path Length Through a Grid With One Allowed Cell Conversion - Amazon (medium)
  • Circular Drone Hub Delivery Route - Amazon (hard)
  • Leaf Domain Cumulative Scores - Amazon (medium)
  • Kth Largest Perfect Binary Subtree - Amazon (medium)
  • Find Conflicting Events - Amazon (medium)
|Home/Coding & Algorithms/Amazon

Build the Largest Available Sequence

Amazon logo
Amazon
Apr 14, 2026, 12:00 AM
mediumSoftware EngineerTake-home ProjectCoding & Algorithms
5
0
Practice Read
Loading...

You are given an integer array values, a binary string state of the same length, and an integer m such that 0 <= m <= values.length.

Build a sequence s of length m using exactly m operations. You may assume it is always possible to complete all m picks.

In each operation:

  1. Choose any index i such that state[i] = '1' .
  2. Append values[i] to s .
  3. Mark that index as unavailable by setting state[i] = '0' .
  4. Then perform one simultaneous availability update on this new state: for every index j > 0 , if state[j - 1] = '1' and state[j] = '0' , flip state[j] to 1 .

Return the lexicographically largest possible sequence s. For integer sequences, lexicographic order compares elements from left to right.

Example:

  • values = [10, 5, 7, 6]
  • state = "0101"
  • m = 2

One optimal answer is [6, 7].

Write a function to compute the lexicographically largest sequence.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Amazon•More Software Engineer•Amazon Software Engineer•Amazon Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.