Bird
Raised Fist0

Given the following code and input arrays A = [2,1,2,4,2,2], B = [5,2,6,2,3,2], what is the output of minDominoRotations(A, B)?

easy🧾 Code Trace Q3 of Q15
Greedy Algorithms - Minimum Domino Rotations
Given the following code and input arrays A = [2,1,2,4,2,2], B = [5,2,6,2,3,2], what is the output of minDominoRotations(A, B)?
A3
B-1
C2
D4
Step-by-Step Solution
Solution:
  1. Step 1: Check candidate A[0] = 2

    Count rotations needed to make all dominoes 2 on top or bottom.
  2. Step 2: Count rotations

    Rotations on top: positions 1 and 3 need rotation (2 rotations), rotations on bottom: positions 1,3,4 need more (3 rotations). Minimum is 2.
  3. Step 3: Check candidate B[0] = 5 if needed

    Since rotations for A[0] candidate is not -1, no need to check B[0].
  4. Final Answer:

    Option C -> Option C
  5. Quick Check:

    Output matches minimal rotations counted [OK]
Quick Trick: Check rotations for candidate on first domino [OK]
Common Mistakes:
MISTAKES
  • Miscounting rotations or returning -1 prematurely
Trap Explanation:
PITFALL
  • Candidates often confuse which side needs rotation or miss counting correctly.
Interviewer Note:
CONTEXT
  • Tests code tracing and rotation counting accuracy.
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