Bird
Raised Fist0

Given the output of the check function is 1 for candidate value 2 on arrays A and B, which of the following input arrays could produce this result?

hard🔄 Reverse Engineer Q9 of Q15
Greedy Algorithms - Minimum Domino Rotations
Given the output of the check function is 1 for candidate value 2 on arrays A and B, which of the following input arrays could produce this result?
AA = [2,1,2,2], B = [2,2,1,2]
BA = [1,1,1,1], B = [2,2,2,2]
CA = [2,2,2,2], B = [1,1,1,1]
DA = [2,3,2,4], B = [2,2,2,2]
Step-by-Step Solution
Solution:
  1. Step 1: Analyze rotations for candidate 2

    Count rotations needed on top and bottom for each option.
  2. Step 2: Calculate rotations for A = [2,1,2,2], B = [2,2,1,2]

    Rotations on top: position 1 (A[1]=1 != 2) -> 1 rotation; rotations on bottom: position 2 (B[2]=1 != 2) -> 1 rotation; minimum is 1.
  3. Step 3: Verify other options

    Options A and B require 0 rotations; A = [2,3,2,4], B = [2,2,2,2] contains invalid values beyond 1 to 6.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Only A = [2,1,2,2], B = [2,2,1,2] matches output 1 rotations [OK]
Quick Trick: Count mismatches per side to find minimal rotations [OK]
Common Mistakes:
MISTAKES
  • Miscounting rotations or ignoring impossible cases
Trap Explanation:
PITFALL
  • Candidates confuse which side requires rotation or misinterpret output.
Interviewer Note:
CONTEXT
  • Tests reverse reasoning from output to input arrays.
Master "Minimum Domino Rotations" in Greedy Algorithms

3 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Greedy Algorithms Quizzes