From a4659f08a701c72c71c862f49821fb4c44084e50 Mon Sep 17 00:00:00 2001 From: xsami Date: Thu, 4 Jan 2024 03:03:34 -0400 Subject: [PATCH] make two arrays equal by reversing subarrays --- ReverseSubArray/reverseSubArray.exs | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 ReverseSubArray/reverseSubArray.exs 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