Minimum Flips to Match Expected Binary Values in a Tree

Problem Overview

  • Compute the minimum number of flip operations to transform initial[] into expected[] on a rooted tree.
  • Input: an undirected tree with nodes 0..n-1 rooted at 0, arrays initial and expected of 0/1; Operation: pick node u and toggle u and all nodes v in u’s subtree where v % 2 == u % 2; Output: the minimum operations.
  • Domain: subtree propagation with parity-based toggles, modeling selective configuration updates.
  • This coding interview problem is a concise interview question on trees and state flips.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: