Пікірлер
@darshankumar5546
@darshankumar5546 17 сағат бұрын
English Explanation: kzbin.info/www/bejne/p6KceKl5gLCBocU
@darshankumar5546
@darshankumar5546 17 сағат бұрын
Hindi Explanation: kzbin.info/www/bejne/p6KceKl5gLCBocU
@darshankumar5546
@darshankumar5546 17 сағат бұрын
class Solution: def shortestDistanceAfterQueries(self, n: int, queries: List[List[int]]) -> List[int]: graph={} for i in range(n-1): graph[i]=[i+1] print(graph) def bfs(graph): nonlocal n queue=deque([(0,0)]) visited=set() visited.add(0) print(queue) while(queue): node,path=queue.popleft() for neighbour in graph[node]: if(neighbour not in visited): if(neighbour==n-1): return path+1 queue.append((neighbour,path+1)) visited.add(neighbour) print(queue) return -1 ans=[] for i,j in queries: print(f"adding edge{i}->{j}") graph[i].append(j) ans.append(bfs(graph)) return ans
@darshankumar5546
@darshankumar5546 17 сағат бұрын
class Solution: def shortestDistanceAfterQueries(self, n: int, queries: List[List[int]]) -> List[int]: graph={} for i in range(n-1): graph[i]=[i+1] print(graph) def bfs(graph): nonlocal n queue=deque([(0,0)]) visited=set() visited.add(0) print(queue) while(queue): node,path=queue.popleft() for neighbour in graph[node]: if(neighbour not in visited): if(neighbour==n-1): return path+1 queue.append((neighbour,path+1)) visited.add(neighbour) print(queue) return -1 ans=[] for i,j in queries: print(f"adding edge{i}->{j}") graph[i].append(j) ans.append(bfs(graph)) return ans
@lowspecster9236
@lowspecster9236 Күн бұрын
Good solution 👍 Need more videos like this.
@darshankumar5546
@darshankumar5546 Күн бұрын
English Explanation: kzbin.info/www/bejne/nX_acmR3f66Hgtk
@darshankumar5546
@darshankumar5546 Күн бұрын
Hindi Explanation: kzbin.info/www/bejne/r6qzmJ2siqifbbM
@darshankumar5546
@darshankumar5546 Күн бұрын
class Solution: def findChampion(self, n: int, edges: List[List[int]]) -> int: winner=set([i for i in range(n)]) looser=set() for i,j in edges: looser.add(j) ans=winner-looser print(ans) ansLen=len(ans) if(ansLen>1): return -1 return ans.pop()
@darshankumar5546
@darshankumar5546 Күн бұрын
class Solution: def findChampion(self, n: int, edges: List[List[int]]) -> int: winner=set([i for i in range(n)]) looser=set() for i,j in edges: looser.add(j) ans=winner-looser print(ans) ansLen=len(ans) if(ansLen>1): return -1 return ans.pop()
@GlynnisGarabedian
@GlynnisGarabedian Күн бұрын
Thanks for the analysis! I need some advice: My OKX wallet holds some USDT, and I have the seed phrase. (alarm fetch churn bridge exercise tape speak race clerk couch crater letter). Could you explain how to move them to Binance?
@darshankumar5546
@darshankumar5546 Күн бұрын
just do a google search, there are multiple videos, available in youtube, as well
@MohamedAasif-vb9xi
@MohamedAasif-vb9xi 2 күн бұрын
Good❤
@darshankumar5546
@darshankumar5546 2 күн бұрын
English Explanation: kzbin.info/www/bejne/q6OnkKOvfdmHqtE
@darshankumar5546
@darshankumar5546 2 күн бұрын
Hindi Explanation: kzbin.info/www/bejne/qYW5cqRml6ishMk
@darshankumar5546
@darshankumar5546 2 күн бұрын
# TC=O( (2*3)! .(2*3))= O(6! .6) # SC=O( (2*3)! ) =O( 6! ) class Solution: def slidingPuzzle(self, board: List[List[int]]) -> int: possibleMoves={ 0:[1,3], 1:[0,2,4], 2:[1,5], 3:[0,4], 4:[1,3,5], 5:[2,4] } def swapPositions(currentState,PositionOfZero,nextPositionOfZero): stateList=list(currentState) stateList[PositionOfZero]=stateList[nextPositionOfZero] stateList[nextPositionOfZero]='0' return ''.join(stateList) visitedState=set() targetState='123450' currentState='' for row in board: for ele in row: currentState+=str(ele) #Ex1->'123405' print(currentState) PositionOfZero=currentState.find('0') queue=deque([(currentState,PositionOfZero,0)]) #BFS while(queue): currentState,PositionOfZero,move=queue.popleft() if(currentState==targetState): return move if(currentState in visitedState): continue visitedState.add(currentState) for nextPositionOfZero in possibleMoves[PositionOfZero]: nextState=swapPositions(currentState,PositionOfZero,nextPositionOfZero) if(nextState not in visitedState): queue.append((nextState,nextPositionOfZero,move+1)) print(queue) return -1 #target= #[ # [1,2,3], # [4,5,0] # ] #[ # [00,01,02], # [10,11,12] # ] #[ # [0,1,2], # [3,4,5] # ] # 00 01 02 10 11 12 # 0 1 2 3 4 5
@darshankumar5546
@darshankumar5546 2 күн бұрын
# TC=O( (2*3)! .(2*3))= O(6! .6) # SC=O( (2*3)! ) =O( 6! ) class Solution: def slidingPuzzle(self, board: List[List[int]]) -> int: possibleMoves={ 0:[1,3], 1:[0,2,4], 2:[1,5], 3:[0,4], 4:[1,3,5], 5:[2,4] } def swapPositions(currentState,PositionOfZero,nextPositionOfZero): stateList=list(currentState) stateList[PositionOfZero]=stateList[nextPositionOfZero] stateList[nextPositionOfZero]='0' return ''.join(stateList) visitedState=set() targetState='123450' currentState='' for row in board: for ele in row: currentState+=str(ele) #Ex1->'123405' print(currentState) PositionOfZero=currentState.find('0') queue=deque([(currentState,PositionOfZero,0)]) #BFS while(queue): currentState,PositionOfZero,move=queue.popleft() if(currentState==targetState): return move if(currentState in visitedState): continue visitedState.add(currentState) for nextPositionOfZero in possibleMoves[PositionOfZero]: nextState=swapPositions(currentState,PositionOfZero,nextPositionOfZero) if(nextState not in visitedState): queue.append((nextState,nextPositionOfZero,move+1)) print(queue) return -1 #target= #[ # [1,2,3], # [4,5,0] # ] #[ # [00,01,02], # [10,11,12] # ] #[ # [0,1,2], # [3,4,5] # ] # 00 01 02 10 11 12 # 0 1 2 3 4 5
@naveennaveen-gp1dn
@naveennaveen-gp1dn 3 күн бұрын
Bro you are doing good but i hope you will continue till you reach the end of leetcode
@darshankumar5546
@darshankumar5546 4 күн бұрын
Hindi Explanation: kzbin.info/www/bejne/fn21iaylf86qa5Y
@darshankumar5546
@darshankumar5546 4 күн бұрын
English Explanation: kzbin.info/www/bejne/d4PRc4GkaJeYg9U
@darshankumar5546
@darshankumar5546 4 күн бұрын
//java import java.lang.Math; class Solution { public long maxMatrixSum(int[][] matrix) { int n=matrix.length; int countOfNegEle=0; long positiveSum=0; int smallestEle=Integer.MAX_VALUE; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ int ele=matrix[i][j]; if(ele<0){ countOfNegEle+=1; ele=ele*(-1); } positiveSum+=ele; smallestEle=Math.min(smallestEle,ele); } } if(countOfNegEle%2==0){ return positiveSum; } return positiveSum-(smallestEle*2); } }
@darshankumar5546
@darshankumar5546 4 күн бұрын
//java import java.lang.Math; class Solution { public long maxMatrixSum(int[][] matrix) { int n=matrix.length; int countOfNegEle=0; long positiveSum=0; int smallestEle=Integer.MAX_VALUE; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ int ele=matrix[i][j]; if(ele<0){ countOfNegEle+=1; ele=ele*(-1); } positiveSum+=ele; smallestEle=Math.min(smallestEle,ele); } } if(countOfNegEle%2==0){ return positiveSum; } return positiveSum-(smallestEle*2); } }
@darshankumar5546
@darshankumar5546 4 күн бұрын
# python # TC=O(n2) # SC=O(1) class Solution: def maxMatrixSum(self, matrix: List[List[int]]) -> int: n=len(matrix) countOfNegEle=0 positiveSum=0 smallestEle=float('inf') for i in range(n): for j in range(n): ele=matrix[i][j] if(ele<0): countOfNegEle+=1 ele=ele*(-1) positiveSum+=ele smallestEle=min(smallestEle,ele) if(countOfNegEle%2==0): return positiveSum return positiveSum-(smallestEle*2) # [ # [1,2,3], # [1,2,3], # [1,2,3] # ]
@darshankumar5546
@darshankumar5546 4 күн бұрын
# python # TC=O(n2) # SC=O(1) class Solution: def maxMatrixSum(self, matrix: List[List[int]]) -> int: n=len(matrix) countOfNegEle=0 positiveSum=0 smallestEle=float('inf') for i in range(n): for j in range(n): ele=matrix[i][j] if(ele<0): countOfNegEle+=1 ele=ele*(-1) positiveSum+=ele smallestEle=min(smallestEle,ele) if(countOfNegEle%2==0): return positiveSum return positiveSum-(smallestEle*2) # [ # [1,2,3], # [1,2,3], # [1,2,3] # ]
@darshankumar5546
@darshankumar5546 4 күн бұрын
Hindi Explanation: kzbin.info/www/bejne/faG0aYR3qcqWjc0si=ryQhALiDZ8itE958
@darshankumar5546
@darshankumar5546 4 күн бұрын
English Explanation: kzbin.info/www/bejne/mKDXlYupfpmXpq8si=RAwzrjNjdMi4OLdB
@darshankumar5546
@darshankumar5546 4 күн бұрын
# Approach-2 OPTIMAL # TC=O(m*n) # SC=O(1) class Solution: def rotateTheBox(self, box: List[List[str]]) -> List[List[str]]: m=len(box) n=len(box[0]) rotatedBox=[['' for _ in range(m)] for _ in range(n)] #print(rotatedBox) #arrange stones for row in box: lowestEmptySpace=-1 for i in range(n-1,-1,-1): #empty if(row[i]=='.'): lowestEmptySpace=max(i,lowestEmptySpace) #obstacle elif(row[i]=='*'): lowestEmptySpace=-1 #stone else: #check if it has empty places towards right if(lowestEmptySpace!=-1): row[lowestEmptySpace]='#' #mark index 'i' as empty row[i]='.' #move pointer above by 1, from previous loc lowestEmptySpace-=1 print(box) for i in range(m): for j in range(n): rotatedBox[j][m-1-i]=box[i][j] return rotatedBox # 00 01 02 03 # 10 11 12 13 # 20 21 22 23 # 00 01 02 # 10 11 12 # 20 21 22 # 30 31 32
@darshankumar5546
@darshankumar5546 4 күн бұрын
# Approach-2 OPTIMAL # TC=O(m*n) # SC=O(1) class Solution: def rotateTheBox(self, box: List[List[str]]) -> List[List[str]]: m=len(box) n=len(box[0]) rotatedBox=[['' for _ in range(m)] for _ in range(n)] #print(rotatedBox) #arrange stones for row in box: lowestEmptySpace=-1 for i in range(n-1,-1,-1): #empty if(row[i]=='.'): lowestEmptySpace=max(i,lowestEmptySpace) #obstacle elif(row[i]=='*'): lowestEmptySpace=-1 #stone else: #check if it has empty places towards right if(lowestEmptySpace!=-1): row[lowestEmptySpace]='#' #mark index 'i' as empty row[i]='.' #move pointer above by 1, from previous loc lowestEmptySpace-=1 print(box) for i in range(m): for j in range(n): rotatedBox[j][m-1-i]=box[i][j] return rotatedBox # 00 01 02 03 # 10 11 12 13 # 20 21 22 23 # 00 01 02 # 10 11 12 # 20 21 22 # 30 31 32
@darshankumar5546
@darshankumar5546 4 күн бұрын
# Approach -1 # TC=O(m*n*log(n)) # SC=O(n) import heapq class Solution: def rotateTheBox(self, box: List[List[str]]) -> List[List[str]]: m=len(box) n=len(box[0]) rotatedBox=[['' for _ in range(m)] for _ in range(n)] #print(rotatedBox) #arrange stones for row in box: maxHeap=[] for i in range(n-1,-1,-1): #empty if(row[i]=='.'): heapq.heappush(maxHeap,-i) #obstacle elif(row[i]=='*'): maxHeap=[] #stone else: #check if it has empty places towards right if(len(maxHeap)!=0): index=heapq.heappop(maxHeap)*(-1) row[index]='#' #mark index 'i' as empty row[i]='.' heapq.heappush(maxHeap,-i) print(box) for i in range(m): for j in range(n): rotatedBox[j][m-1-i]=box[i][j] return rotatedBox # 00 01 02 03 # 10 11 12 13 # 20 21 22 23 # 00 01 02 # 10 11 12 # 20 21 22 # 30 31 32
@darshankumar5546
@darshankumar5546 4 күн бұрын
# Approach -1 # TC=O(m*n*log(n)) # SC=O(n) import heapq class Solution: def rotateTheBox(self, box: List[List[str]]) -> List[List[str]]: m=len(box) n=len(box[0]) rotatedBox=[['' for _ in range(m)] for _ in range(n)] #print(rotatedBox) #arrange stones for row in box: maxHeap=[] for i in range(n-1,-1,-1): #empty if(row[i]=='.'): heapq.heappush(maxHeap,-i) #obstacle elif(row[i]=='*'): maxHeap=[] #stone else: #check if it has empty places towards right if(len(maxHeap)!=0): index=heapq.heappop(maxHeap)*(-1) row[index]='#' #mark index 'i' as empty row[i]='.' heapq.heappush(maxHeap,-i) print(box) for i in range(m): for j in range(n): rotatedBox[j][m-1-i]=box[i][j] return rotatedBox # 00 01 02 03 # 10 11 12 13 # 20 21 22 23 # 00 01 02 # 10 11 12 # 20 21 22 # 30 31 32
@darshankumar5546
@darshankumar5546 5 күн бұрын
Proud to say, my solution is better than, leetcode's official solution😇
@darshankumar5546
@darshankumar5546 5 күн бұрын
Proud to say, my solution is better than, leetcode's official solution😇
@darshankumar5546
@darshankumar5546 5 күн бұрын
Hindi Explanation: kzbin.info/www/bejne/inquh3iqm9-dnsk
@darshankumar5546
@darshankumar5546 5 күн бұрын
# solution better than leetcode's official solution class Solution: def maxEqualRowsAfterFlips(self, matrix: List[List[int]]) -> int: m=len(matrix) n=len(matrix[0]) nums=[] for num in matrix: l=len(num) val=0 for i in range(l): val+=(num[i])*(2**(l-i-1)) nums.append(val) print(nums) visited=set() eligible=set([0,(2**(n))-1]) MaxAns=0 for i in range(m): if(i in visited): continue ans=1 for j in range(i+1,m): if(j in visited): continue if((nums[i]^nums[j]) in eligible): ans+=1 visited.add(j) MaxAns=max(MaxAns,ans) visited.add(i) print(f"{ans} nos has same BITpattern as that of:{nums[i]}") return MaxAns # [ # [0,0,0], # [0,0,1], # [1,1,0] # ] # [0,0,1] # -->[0,0,1] # -->[1,1,0] # xor result shld be: # [0,0,0] or [1,1,1] # decimal: 0 or 7 (2**3 -1)
@darshankumar5546
@darshankumar5546 5 күн бұрын
English Explanation: kzbin.info/www/bejne/gZvJlnZuopmrb7c
@darshankumar5546
@darshankumar5546 5 күн бұрын
# SOLUTION better than leetcode's official solution: class Solution: def maxEqualRowsAfterFlips(self, matrix: List[List[int]]) -> int: m=len(matrix) n=len(matrix[0]) nums=[] for num in matrix: l=len(num) val=0 for i in range(l): val+=(num[i])*(2**(l-i-1)) nums.append(val) print(nums) visited=set() eligible=set([0,(2**(n))-1]) MaxAns=0 for i in range(m): if(i in visited): continue ans=1 for j in range(i+1,m): if(j in visited): continue if((nums[i]^nums[j]) in eligible): ans+=1 visited.add(j) MaxAns=max(MaxAns,ans) visited.add(i) print(f"{ans} nos has same BITpattern as that of:{nums[i]}") return MaxAns # [ # [0,0,0], # [0,0,1], # [1,1,0] # ] # [0,0,1] # -->[0,0,1] # -->[1,1,0] # xor result shld be: # [0,0,0] or [1,1,1] # decimal: 0 or 7 (2**3 -1)
@darshankumar5546
@darshankumar5546 6 күн бұрын
English Explanation: kzbin.info/www/bejne/bJSthoeqe82nacU
@darshankumar5546
@darshankumar5546 6 күн бұрын
Hindi Explanation: kzbin.info/www/bejne/b6arlXaGitKepsk
@darshankumar5546
@darshankumar5546 6 күн бұрын
# TC=O(m.n+g(m+n)) # SC=O(M.n) class Solution: def countUnguarded(self, m: int, n: int, guards: List[List[int]], walls: List[List[int]]) -> int: grid=[[0 for _ in range(n)] for _ in range(m)] # mark the walls for i,j in walls: grid[i][j]=-1 for i,j in guards: grid[i][j]=-1 def markGuardedCells(i,j): nonlocal grid print(i,j) #go right for e in range(j+1,n): print('right->',i,e) if(grid[i][e]==-1): break elif(grid[i][e]==1): pass else: grid[i][e]=1 #go left for e in range(j-1,-1,-1): print('left->',i,e) if(grid[i][e]==-1): break elif(grid[i][e]==1): pass else: grid[i][e]=1 #go up for e in range(i-1,-1,-1): print('up->',e,j) if(grid[e][j]==-1): break elif(grid[e][j]==1): pass else: grid[e][j]=1 #go down for e in range(i+1,m): print('down->',e,j) if(grid[e][j]==-1): break elif(grid[e][j]==1): pass else: grid[e][j]=1 for i,j in guards: markGuardedCells(i,j) print(grid) ans=0 for i in range(m): for j in range(n): if(grid[i][j]==0): ans+=1 return ans
@darshankumar5546
@darshankumar5546 6 күн бұрын
# TC=O(m.n+g(m+n)) # SC=O(M.n) class Solution: def countUnguarded(self, m: int, n: int, guards: List[List[int]], walls: List[List[int]]) -> int: grid=[[0 for _ in range(n)] for _ in range(m)] # mark the walls for i,j in walls: grid[i][j]=-1 for i,j in guards: grid[i][j]=-1 def markGuardedCells(i,j): nonlocal grid print(i,j) #go right for e in range(j+1,n): print('right->',i,e) if(grid[i][e]==-1): break elif(grid[i][e]==1): pass else: grid[i][e]=1 #go left for e in range(j-1,-1,-1): print('left->',i,e) if(grid[i][e]==-1): break elif(grid[i][e]==1): pass else: grid[i][e]=1 #go up for e in range(i-1,-1,-1): print('up->',e,j) if(grid[e][j]==-1): break elif(grid[e][j]==1): pass else: grid[e][j]=1 #go down for e in range(i+1,m): print('down->',e,j) if(grid[e][j]==-1): break elif(grid[e][j]==1): pass else: grid[e][j]=1 for i,j in guards: markGuardedCells(i,j) print(grid) ans=0 for i in range(m): for j in range(n): if(grid[i][j]==0): ans+=1 return ans
@darshankumar5546
@darshankumar5546 7 күн бұрын
English Explanation: kzbin.info/www/bejne/mHPTmXidoqZ5b6c
@darshankumar5546
@darshankumar5546 7 күн бұрын
HINDI explanation: kzbin.info/www/bejne/hJzOZGODmq-CpbM
@darshankumar5546
@darshankumar5546 7 күн бұрын
class Solution: def takeCharacters(self, s: str, k: int) -> int: charFreq_Array=[0,0,0] for i in s: charFreq_Array[ord(i)-ord('a')]+=1 print(charFreq_Array) if(min(charFreq_Array)<k): return -1 charFreq_window=[0,0,0] start=0 maxWindowLen=0 n=len(s) for end in range(n): index=ord(s[end])-ord('a') charFreq_window[index]+=1 print(s[start:end+1],start,end,charFreq_window,charFreq_Array) while((charFreq_Array[index]-charFreq_window[index])<k and (start<=end)): charFreq_window[ord(s[start])-ord('a')]-=1 start+=1 print(f"removing 1st elelemt of window, till {chr(index+ord('a'))} is removed:",s[start:end+1]) maxWindowLen=max(maxWindowLen,end-start+1) print('max Len of window seen till now=',maxWindowLen) return n-maxWindowLen # s = "aabaaaacaabc", k = 2 # [a-8, b-2,c-2] # window=[] curWinLen=4 maxWinLen=4 # n=12 # 12-4=8 # # n
@darshankumar5546
@darshankumar5546 7 күн бұрын
class Solution: def takeCharacters(self, s: str, k: int) -> int: charFreq_Array=[0,0,0] for i in s: charFreq_Array[ord(i)-ord('a')]+=1 print(charFreq_Array) if(min(charFreq_Array)<k): return -1 charFreq_window=[0,0,0] start=0 maxWindowLen=0 n=len(s) for end in range(n): index=ord(s[end])-ord('a') charFreq_window[index]+=1 print(s[start:end+1],start,end,charFreq_window,charFreq_Array) while((charFreq_Array[index]-charFreq_window[index])<k and (start<=end)): charFreq_window[ord(s[start])-ord('a')]-=1 start+=1 print(f"removing 1st elelemt of window, till {chr(index+ord('a'))} is removed:",s[start:end+1]) maxWindowLen=max(maxWindowLen,end-start+1) print('max Len of window seen till now=',maxWindowLen) return n-maxWindowLen # s = "aabaaaacaabc", k = 2 # [a-8, b-2,c-2] # window=[] curWinLen=4 maxWinLen=4 # n=12 # 12-4=8 # # n
@darshankumar5546
@darshankumar5546 8 күн бұрын
English Explanation: kzbin.info/www/bejne/eH_ainx3mNqfiK8
@darshankumar5546
@darshankumar5546 8 күн бұрын
Hindi explanation: kzbin.info/www/bejne/l4nGfnSKZqyefqc
@darshankumar5546
@darshankumar5546 8 күн бұрын
class Solution: def maximumSubarraySum(self, nums: List[int], k: int) -> int: n=len(nums) a={} maxSubArraySum=0 SubArraySum=0 begin=0 end=0 i=0 while(i<n): #window has space to insert the new ele if(nums[i] in a): print(f"{nums[i]} already in window, remove elements from start of window, till {nums[i]} is present") while(begin<a[nums[i]]): print(f"removing {nums[begin]} of index:{begin} from window") SubArraySum-=nums[begin] a.pop(nums[begin]) begin+=1 print('window=',nums[begin:end]) SubArraySum-=nums[begin] print(f"removing {nums[begin]} of index:{begin} from window") a.pop(nums[begin]) begin+=1 a[nums[i]]=i end+=1 SubArraySum+=nums[i] print('window=',nums[begin:end],f"begin={begin},end={end}",a) #if window is already having K elements, make space for next element if((end-begin)==k): maxSubArraySum=max(maxSubArraySum,SubArraySum) print(f"max Len-K sub array sum={maxSubArraySum}; curreent subArray sum={SubArraySum}") SubArraySum-=nums[begin] print(f"removing {nums[begin]} of index:{begin} from window,to make space for next ele") a.pop(nums[begin]) begin+=1 print('window=',nums[begin:end]) i+=1 return maxSubArraySum # nums = [1,5,4,2,9,9,9], k = 3 # window=[9] maxSubArraySum(len_k) =15
@darshankumar5546
@darshankumar5546 8 күн бұрын
class Solution: def maximumSubarraySum(self, nums: List[int], k: int) -> int: n=len(nums) a={} maxSubArraySum=0 SubArraySum=0 begin=0 end=0 i=0 while(i<n): #window has space to insert the new ele if(nums[i] in a): print(f"{nums[i]} already in window, remove elements from start of window, till {nums[i]} is present") while(begin<a[nums[i]]): print(f"removing {nums[begin]} of index:{begin} from window") SubArraySum-=nums[begin] a.pop(nums[begin]) begin+=1 print('window=',nums[begin:end]) SubArraySum-=nums[begin] print(f"removing {nums[begin]} of index:{begin} from window") a.pop(nums[begin]) begin+=1 a[nums[i]]=i end+=1 SubArraySum+=nums[i] print('window=',nums[begin:end],f"begin={begin},end={end}",a) #if window is already having K elements, make space for next element if((end-begin)==k): maxSubArraySum=max(maxSubArraySum,SubArraySum) print(f"max Len-K sub array sum={maxSubArraySum}; curreent subArray sum={SubArraySum}") SubArraySum-=nums[begin] print(f"removing {nums[begin]} of index:{begin} from window,to make space for next ele") a.pop(nums[begin]) begin+=1 print('window=',nums[begin:end]) i+=1 return maxSubArraySum # nums = [1,5,4,2,9,9,9], k = 3 # window=[9] maxSubArraySum(len_k) =15
@darshankumar5546
@darshankumar5546 9 күн бұрын
if you felt, this question is easy, try this Day 17 question : kzbin.info/www/bejne/p4G5lYdojJuSqKM ( very proud to say my solution is even more optimal than official leetcode solution, see the video for day 17 for details )
@darshankumar5546
@darshankumar5546 9 күн бұрын
if you solved this question easily, try this question: kzbin.info/www/bejne/p4G5lYdojJuSqKM
@darshankumar5546
@darshankumar5546 9 күн бұрын
ENGLISH explanation: kzbin.info/www/bejne/jmWUqGV4bt6rldUsi=Zv7LJ2kXLv3ZEKgp
@darshankumar5546
@darshankumar5546 9 күн бұрын
HINDI explanation: kzbin.info/www/bejne/bXKrZ4Jsi7WDba8