diff --git a/src/maximum_element_after_decreasing_and_rearranging.py b/src/maximum_element_after_decreasing_and_rearranging.py new file mode 100644 index 0000000..ac52369 --- /dev/null +++ b/src/maximum_element_after_decreasing_and_rearranging.py @@ -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 diff --git a/tests/test_maximum_element_after_decreasing_and_rearranging.py b/tests/test_maximum_element_after_decreasing_and_rearranging.py new file mode 100644 index 0000000..53d2b92 --- /dev/null +++ b/tests/test_maximum_element_after_decreasing_and_rearranging.py @@ -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 + )