This is a verified interview question from Amazon. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Smart City Security Unit Relocation" covers key patterns like Arrays.
"In Amazon's Smart Cities Management System, each city has a given population, and some cities are equipped with security units. You are given: An integer array population of size n, where population[i] represents the number of inhabitants in the iᵗʰ city. A binary string unit of length n, where: unit[i] = '1' means city i has a security unit. unit[i] = '0' means city i does not have a security unit. Relocation Rules A security unit at city i (where i > 1) can be moved one step to the left, i.e., to city i - 1. Each unit can be moved at most once. If moved, city i loses its unit and city i - 1 gains one. The security unit in city 1 cannot be moved further left. A city is considered protected if it has a security unit after all relocations. Your task is to determine the maximum total population that can be protected after applying optimal relocations. Example Input: population = [10, 5, 8, 9, 6] unit = "01101" Process: Initial configuration: 01101 Move unit from index 2 → 1: 10101 Safe population = 10 + 8 + 6 = 24 Move unit from index 5 → 4: 10110 Safe population = 10 + 8 + 9 = 27 No better configuration exists. Output: 27"
Join thousands of developers practicing for Amazon.