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.