Skip to content

Commit a18f71b

Browse files
committed
1299. Replace Elements with Greatest Element on Right Side.
- Language: Python. - Time complexity: O(n^2). - Space complexity: O(1). - Method: Brute Force.
1 parent 831d7fb commit a18f71b

File tree

3 files changed

+10251
-0
lines changed

3 files changed

+10251
-0
lines changed

python_solutions/lc_1299_replace_elements_with_gt_element_on_right/__init__.py

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def replaceElements(self, arr: list[int]) -> list[int]:
3+
# Time complexity: O(n^2). Space complexity: O(1).
4+
# Method: brute force
5+
for i in range(len(arr) - 1):
6+
mx = i + 1
7+
for j in range(i + 2, len(arr)):
8+
if arr[mx] < arr[j]:
9+
mx = j
10+
arr[i] = arr[mx]
11+
arr[-1] = -1
12+
return arr

0 commit comments

Comments
 (0)