This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def numIslands(self, grid: List[List[str]]) -> int: | |
num_rows,num_cols,num_islands = len(grid), len(grid[0]),0 | |
visited = set() | |
def findIsland(row,col): | |
# add this cell to the visited set | |
visited.add((row,col)) | |
# add left, right, top and down neighbours of this cell respectively. Here the first element is row id and second one is the column id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def coinChange(self, coins: List[int], amount: int) -> int: | |
# Create a dp array for 0 to amount (inclusive) with the max values | |
dp = [float('inf')] * (amount+1) | |
# Initialize the value of the dp array | |
dp[0] = 0 | |
# Let's compute dp array for all values from 1 to amount | |
for i in range(1, amount+1): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def getModifiedArray(self, length: int, updates: List[List[int]]) -> List[int]: | |
# Initialize an array of length+1 with all values as 0 | |
arr = [0] * (length+1) | |
# Iterate over all the given ranges | |
for start, end, value in updates: | |
''' | |
Just update the start index with +val and end+1 with -val as we need to see the effect till end | |
We will use the prefix sum to retrive the actual sum, later |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int: | |
for r,c in ops: | |
# expand and shrink the matrix size (bottom-right boundry of matrix) based on the current operation | |
m = min(m,r) | |
n = min(c,n) | |
# total number of elements will be multiplication of bottom and right boundry asssming left and top boundry is 0,0 | |
return m*n | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kubectl set image pod podname nginx=nginx:1.15-alpine | |
kubectl edit pod podName | |
# Create the nginx pod with version 1.17.4 and expose it on port 80 | |
kubectl run nginx --image=nginx:1.17.4 --restart=Never --port= | |
kubectl run nginx-pod --image=nginx:alpine # will create a pod with name nginx-pod | |
# add the command in the pod | |
command: ['sleep', '5000'] |
OlderNewer