Source Code: class Solution: def finalPrices(self, prices: List[int]) -> List[int]: ''' To solve this problem, I realized that I could just brute force the solution, as there are only 500 elements and 500 squared isn't too big of a number to have to iterate, so time complexity of N^2 should be fine here. We can see that for each element in the array we check the elements to the right of it, and the moment we see an element that is smaller than the number where we were initially, we subtract that smaller number from our original number at the current index, and we repeat this process until we've gone through the entire array! :D ''' n = len(prices) for i in range(n): for j in range(i+1,n): if prices[j]
Source Code:
class Solution:
def finalPrices(self, prices: List[int]) -> List[int]:
'''
To solve this problem, I realized that I could just brute force
the solution, as there are only 500 elements and 500 squared isn't
too big of a number to have to iterate, so time complexity of N^2
should be fine here. We can see that for each element in the array
we check the elements to the right of it, and the moment we see an
element that is smaller than the number where we were initially,
we subtract that smaller number from our original number at the
current index, and we repeat this process until we've gone through
the entire array! :D
'''
n = len(prices)
for i in range(n):
for j in range(i+1,n):
if prices[j]