PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Amazon

Maximize protected population and bitwise AND

Last updated: Mar 29, 2026

Quick Overview

This paired problem evaluates array manipulation and resource-allocation reasoning for maximizing covered population in a constrained-movement scenario, alongside bitwise manipulation and combinatorial optimization for maximizing a bitwise AND under limited increments.

  • hard
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Maximize protected population and bitwise AND

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Take-home Project

You are given two independent coding problems. ## Problem 1: Maximize protected population after moving units There are **n** cities in a line (indexed **1..n**). City *i* has population `population[i]`. Initially, some cities contain **one** security unit and others contain **none**. You are given an array `unit[i]` where: - `unit[i] = 1` means city *i* initially has one unit - `unit[i] = 0` means it has no unit You may **reassign** units using these rules: - Each security unit may move **at most one city to the left** (from city *i* to city *i-1*). - Each security unit can be moved **at most once** (so it either stays, or moves left by 1). - A unit in city **1** cannot move left. - After all moves, a city is considered **protected** if it contains **at least one** unit (multiple units in one city are allowed but do not add extra benefit). **Goal:** After performing moves, maximize the **total population of protected cities**. **Task:** Return the maximum possible protected population sum. --- ## Problem 2: Maximize bitwise AND after at most k increments You are given an array `customer_rating` of length **n** (assume all values are non-negative integers). You may perform the following operation **at most k times** in total: - Choose any index `i` and do `customer_rating[i] += 1`. After performing up to **k** increments, you must: - Choose **exactly m** elements from the final array (any indices you want), and - Compute the **bitwise AND** of those **m** chosen values. Call the result `new_rating`. **Goal:** Maximize `new_rating`. **Task:** Return the maximum possible `new_rating` achievable with at most `k` total `+1` operations.

Quick Answer: This paired problem evaluates array manipulation and resource-allocation reasoning for maximizing covered population in a constrained-movement scenario, alongside bitwise manipulation and combinatorial optimization for maximizing a bitwise AND under limited increments.

Related Interview Questions

  • Find Unique Target-Sum Pairs - Amazon (easy)
  • Find Valid IP Addresses in Files - Amazon (medium)
  • Implement Optimal Bucket Batching - Amazon (hard)
  • Implement Cache and Rotate Matrix - Amazon (medium)
  • Find Longest Activatable Server Streak - Amazon (hard)
Amazon logo
Amazon
Feb 12, 2026, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
14
0
Loading...

You are given two independent coding problems.

Problem 1: Maximize protected population after moving units

There are n cities in a line (indexed 1..n). City i has population population[i].

Initially, some cities contain one security unit and others contain none. You are given an array unit[i] where:

  • unit[i] = 1 means city i initially has one unit
  • unit[i] = 0 means it has no unit

You may reassign units using these rules:

  • Each security unit may move at most one city to the left (from city i to city i-1 ).
  • Each security unit can be moved at most once (so it either stays, or moves left by 1).
  • A unit in city 1 cannot move left.
  • After all moves, a city is considered protected if it contains at least one unit (multiple units in one city are allowed but do not add extra benefit).

Goal: After performing moves, maximize the total population of protected cities.

Task: Return the maximum possible protected population sum.

Problem 2: Maximize bitwise AND after at most k increments

You are given an array customer_rating of length n (assume all values are non-negative integers).

You may perform the following operation at most k times in total:

  • Choose any index i and do customer_rating[i] += 1 .

After performing up to k increments, you must:

  • Choose exactly m elements from the final array (any indices you want), and
  • Compute the bitwise AND of those m chosen values. Call the result new_rating .

Goal: Maximize new_rating.

Task: Return the maximum possible new_rating achievable with at most k total +1 operations.

Comments (0)

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 7,500+ 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
  • Compare Platforms
  • Discord Community

Support

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

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.