Skip to content

Commit

Permalink
make two arrays equal by reversing subarrays
Browse files Browse the repository at this point in the history
  • Loading branch information
xsami committed Jan 4, 2024
1 parent 834f6f1 commit a4659f0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ReverseSubArray/reverseSubArray.exs
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a4659f0

Please sign in to comment.