Skip to content

Instantly share code, notes, and snippets.

View amarjitdhillon's full-sized avatar
🎯
Focusing

Amarjit Singh Dhillon amarjitdhillon

🎯
Focusing
View GitHub Profile
@amarjitdhillon
amarjitdhillon / number-of-islands.py
Created February 11, 2022 23:14
Number of Islands
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
@amarjitdhillon
amarjitdhillon / coin-change.py
Created February 12, 2022 05:21
Coin Change
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):
@amarjitdhillon
amarjitdhillon / range-addition.py
Created February 12, 2022 06:44
Range Addition
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
@amarjitdhillon
amarjitdhillon / range-addition-ii.py
Created February 12, 2022 08:07
Range Addition II
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
@amarjitdhillon
amarjitdhillon / ckad-cheat-sheet.sh
Created February 12, 2022 08:54
CKAD exam cheatsheet
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']