Skip to content

Commit

Permalink
"Find The Original Array of Prefix Xor" solution
Browse files Browse the repository at this point in the history
  • Loading branch information
lancelote committed Oct 31, 2023
1 parent 53deda6 commit f39b358
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/find_the_original_array_of_prefix_xor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution:
def findArray(self, pref: list[int]) -> list[int]:
rolling = pref[0]
res = [pref[0]]

for i in range(1, len(pref)):
new_x = rolling ^ pref[i]
rolling ^= new_x
res.append(new_x)

return res
14 changes: 14 additions & 0 deletions tests/test_find_the_original_array_of_prefix_xor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pytest

from src.find_the_original_array_of_prefix_xor import Solution


@pytest.mark.parametrize(
"pref,expected",
(
([5, 2, 0, 3, 1], [5, 7, 2, 3, 2]),
([13], [13]),
),
)
def test_solution(pref, expected):
assert Solution().findArray(pref) == expected

0 comments on commit f39b358

Please sign in to comment.