Facebook | Phone | Reverse To Make Equal

Given two arrays A & B of Length N, determine if there is a way to make A equal to B by reversing any subarrays from array B any number of times.

Signature:
bool areTheyEqual(int[] arr_a, int[] arr_b)

input
All integers in array are in the range [0, 1,000,000,000]

output
Return true if B can be made equal to A, Return false otherwise.

 Example:
 A = [1, 2, 3, 4]
 B = [1, 4, 3, 2]
 output = true

 After reversing the subarray of B from indices 1 to 3, array B will equal array A.
 
 If anyone have a good answer for it?
Comments (55)