Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Problem1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#Paint House

#Time complexity = O(n*3) so basically On
#Space complexity O1
#for each new house check the minimium to cost with each of the colors, by choosing the minimum possible till previous house from the remaining colors

class Solution:
def minCost(self, costs: List[List[int]]) -> int:
red = costs[0][0]
blue = costs[0][1]
green = costs[0][2]

for i in range(1, len(costs)):
oldRed = red
red = costs[i][0] + min(blue, green)

oldBlue = blue
blue = costs[i][1] + min(oldRed, green)

green = costs[i][2] + min(oldRed, oldBlue)

return min(red,min(green,blue))
18 changes: 18 additions & 0 deletions Problem2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#Coin Change II

#Time complexity = O(n+1*m+1) where n is length of coins and m is the amount
#Space complexity O(m+1)

class Solution:
def change(self, amount: int, coins: List[int]) -> int:
arr = [0]*(amount+1)
arr[0] = 1

for coin in coins:
for j in range(0,amount+1):
noChoose = arr[j]
choose = 0
if j >=coin:
choose = arr[j-coin]
arr[j] = choose + noChoose
return arr[amount]