Skip to main content
Back to problems
Leetcode
Medium
Arrays
Bit Manipulation
Greedy
Construct The Minimum Bitwise Array I

Construct an array of the same length where each position is chosen to make the resulting bitwise property as small as possible under the problem's rule.

Acceptance 0%
Problem Statement

Given an integer array nums, construct a new array ans of the same length by choosing a value for each position according to the bitwise rule implied by the problem. The goal is to make each chosen value as small as possible while still satisfying the required condition.

This is a constructive bitwise problem: inspect each number independently, apply the smallest valid transformation, and return the resulting array.

Input Format

  • An integer array nums.
  • Each element is a non-negative integer.

Output Format

  • Return an integer array ans of the same length.
  • ans[i] should be the minimum valid value for position i under the given bitwise condition.

Constraints

  • 1 <= nums.length
  • Values are integers in a typical 32-bit range.
  • The exact bitwise rule is problem-specific; solve each element using bit operations and constructive reasoning.
Examples
Sample cases returned by the problem API.

Example 1

Input

nums = [2, 3, 5]

Output

[1, 1, 4]

Explanation

Illustrative example: each value is transformed independently into the smallest number that satisfies the required 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.