Learn DSADSAContests
coding75 logo
LeetCode POTDPOTDSheets
coding75 Pro
coding75 logo
Dashboard
Learn DSA
Course RoadmapFlow
DSA Topic TreeNew 🚀
Contest SolutionsPractice
Practice Sheets
MasterclassesLive 👨🏻‍💻

coding75 ProPRO

Live Classes & Placement Guidance

coding75 logo

The premier developer platform for mastering Data Structures & Algorithms, exploring contest editorials, building ATS-ready resumes, and accelerating your tech career.

Connect & Community

DSA & Contests

  • Learn DSA
  • Contest Solutions
  • LeetCode POTDDaily
  • Practice Sheets
  • MasterclassesSoon

Interview Prep

  • Portfolio Projects
  • CS Fundamentals
  • System DesignSoon
  • Interview ExperiencesSoon
  • Mock InterviewsSoon

Career & Pro

  • Jobs & Internships
  • Resume BuilderATS
  • coding75 Pro
  • Submit Feedback
© 2026coding75•crackDSA™•Maa Lalita Edtech Private Limited. All Rights Reserved.
Privacy PolicyTerms & ConditionsContact Support
Registered Office: Kanpur 208021•Regional Office: Indiranagar, Bangalore, 560008
Maa Lalita Edtech Private Limited
Contests/LeetCode/Weekly Contest 407/3226. Number of Bit Changes to Make Two Integers Equal
Next
LeetCodeLeetCode
Easy
Weekly Contest 407

3226. Number of Bit Changes to Make Two Integers Equal

Bit ManipulationArray
Loading...
Solve on LeetCode

Problem Statement

Official algorithmic problem description and constraints.

Open on LeetCode

You are given two positive integers n and k.

You can choose any bit in the binary representation of n that is equal to 1 and change it to 0.

Return the number of changes needed to make n equal to k. If it is impossible, return -1.

 

Example 1:

Input: n = 13, k = 4

Output: 2

Explanation:

Initially, the binary representations of n and k are n = (1101)2 and k = (0100)2.

We can change the first and fourth bits of n. The resulting integer is n = (0100)2 = k.

Example 2:

Input: n = 21, k = 21

Output: 0

Explanation:

n and k are already equal, so no changes are needed.

Example 3:

Input: n = 14, k = 13

Output: -1

Explanation:

It is not possible to make n equal to k.

 

Constraints:

  • 1 <= n, k <= 106


Solutions & Walkthrough

Detailed video explanations, mathematical intuition, and clean C++ implementation code.

Connecting secure classroom stream...
Back to Weekly Contest 407
Next Problem