Google Interview Question | Need Help
Anonymous User
1638

Problem Statement
Given an array of integers ( A ), and two integers ( S ) (start value) and ( D ) (destination value), you are allowed to perform any of the following operations on a value ( x ):

  1. Add an element from ( A ) to ( x ): ( x + A[i] )
  2. Subtract an element from ( A ) from ( x ): ( x - A[i] )
  3. Perform a bitwise XOR of an element from ( A ) with ( x ): ( x XOR A[i] )

Each operation counts as one move. Determine the minimum number of moves required to transform the integer ( S ) into the integer ( D ) using the operations above. If it's not possible to achieve this transformation, return (-1).Input( A ): An array of integers.( S ): The starting integer.( D ): The target integer.
OutputThe minimum number of moves required to convert ( S ) to ( D ), or (-1) if it's impossible.Example Test CaseInput:
A = [6, 2, 7, 7]
S = 10
D = 21
Output:3

Comments (6)