Skip to content

Commit

Permalink
"Maximum Element After Decreasing and Rearranging" solution
Browse files Browse the repository at this point in the history
  • Loading branch information
lancelote committed Nov 16, 2023
1 parent a3328fc commit 89aeb38
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/maximum_element_after_decreasing_and_rearranging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution:
def maximumElementAfterDecrementingAndRearranging(
self, arr: list[int]
) -> int:
arr = sorted(arr)

last = 0

for x in arr:
if x > last + 1:
last = last + 1
else:
last = x

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

from src.maximum_element_after_decreasing_and_rearranging import Solution


@pytest.mark.parametrize(
"arr,expected",
(
([2, 2, 1, 2, 1], 2),
([100, 1, 1000], 3),
([1, 2, 3, 4, 5], 5),
),
)
def test_solution(arr, expected):
assert (
Solution().maximumElementAfterDecrementingAndRearranging(arr)
== expected
)

0 comments on commit 89aeb38

Please sign in to comment.