Skip to content

Commit

Permalink
feat: replace remove
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwin-nair98 committed Mar 6, 2024
1 parent 735c5a8 commit 322f1a2
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions elements/6_4_Replace_Remove/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Question: Replace a by two d's and remove b's


def replaceAndRemove(arr):
n = len(arr)
i = 0
while i < n:
if arr[i] == "b":
del arr[i]
i -= 1
n -= 1
elif arr[i] == "a":
del arr[i]
arr.append("d")
arr.append("d")
i -= 1
n += 1
i += 1
return arr


print("Replace: " + str(replaceAndRemove(["a", "b", "c", "v"])))

0 comments on commit 322f1a2

Please sign in to comment.