Skip to main content
Back to problems
Leetcode
Medium
Arrays
Bit Manipulation
Math
Construct the Minimum Bitwise Array II

Construct an array where each value is the smallest valid number satisfying a bitwise condition.

Acceptance 0%
Problem Statement

You are given an array of positive integers. For each element, construct a replacement value that is the smallest integer satisfying the problem’s bitwise constraint for that position, and return the resulting array.

The key challenge is to reason about the binary representation of each number and determine the minimum valid choice without brute force search over all integers.

Input Format

  • An integer array nums.
  • Each nums[i] represents the original value at position i.

Use the problem’s bitwise rule to compute the transformed array.

Output Format

  • Return an integer array containing the minimum valid replacement for each position.

Constraints

  • The input size and value ranges are assumed to be within standard interview/contest limits.
  • All values are positive integers.
  • The construction should run efficiently without exhaustive search.
Examples
Sample cases returned by the problem API.

Example 1

Input

nums = [3, 5, 7]

Output

[1, 1, 1]

Explanation

This illustrative example shows the idea of independently replacing each value with the smallest valid one under a bitwise rule.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.