diff --git a/ReverseSubArray/reverseSubArray.exs b/ReverseSubArray/reverseSubArray.exs new file mode 100644 index 0000000..649bd28 --- /dev/null +++ b/ReverseSubArray/reverseSubArray.exs @@ -0,0 +1,8 @@ +# Solution for: https://leetcode.com/problems/make-two-arrays-equal-by-reversing-subarrays/description/ +defmodule Solution do + @spec can_be_equal(target :: [integer], arr :: [integer]) :: boolean + def can_be_equal(target, arr) do + new_arr = arr |> Enum.sort + target |> Enum.sort |> Enum.with_index |> Enum.all?(fn({number, index}) -> number === Enum.at(new_arr, index) end) + end +end