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'] |
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
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 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 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 merge(self, intervals: List[List[int]]) -> List[List[int]]: | |
# sort the intervals by the start value, in case they are not sorted by default | |
intervals.sort(key = lambda x: x[0]) | |
# edge case. If num elements is one, then return the same list | |
if len(intervals) == 1: | |
return intervals | |
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 kthFactor(self, n: int, k: int) -> int: | |
# counter represent the i^th factor of the number found so far | |
counter = 0 | |
# go over the number from 1 to n as we need to divide the n by this number to find if that number is a factor | |
for i in range(1, n+1): | |
if n%i == 0: |
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 mostVisitedPattern(self, username: List[str], timestamp: List[int], website: List[str]) -> List[str]: | |
# zip the time, user and website to one list | |
tuw = list(zip(timestamp,username,website)) | |
# we need to sort them by time --> username --> website | |
sorted_tuw = sorted(tuw) | |
# We will polulate a user history hashmap of various pages visited. The hashmap is of type {user: [pages]} |
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 ParkingSystem: | |
# initialize the parking object | |
def __init__(self, big: int, medium: int, small: int): | |
# to hold various types of parking we are using a dict in constructor | |
self.lot = {} | |
# add the parking counters in this lot dict | |
self.lot[1] = big | |
self.lot[2] = medium | |
self.lot[3] = small |
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 wordPattern(self, pattern: str, s: str) -> bool: | |
hm = {} | |
# we need to split the s over the space(" ") | |
s = s.split(" ") | |
# if the lengths of pattern and s are not same then return False | |
if len(s) != len(pattern): | |
return False |
NewerOlder