Grid Game | Leetcode 2017

preview_player
Показать описание
This vido explains Grid Game using the most optimal approach.
----------------------------------------------------------------------------------------------------------------------------------------------------------------
🟣 JOIN our 𝐋𝐈𝐕𝐄 𝐢𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐭𝐫𝐚𝐢𝐧𝐢𝐧𝐠 𝐩𝐫𝐨𝐠𝐫𝐚𝐦 through whatsapp query: +91 8918633037
---------------------------------------------------------------------------------------------------------------------------------------------------------------

Рекомендации по теме
Комментарии
Автор

Watched video till 12:26 and coded on my own. Thanks for the crystal clear intuition

beinghappy
Автор

The best explanation of today's problem on Youtube - Thank you so much 💙 for such a great explanation!

touhidiutcse
Автор

finally understood it, thank you so much

yashh
Автор

python corrected: class Solution(object):
def gridGame(self, grid):
n = len(grid[0])
if n < 2:
return 0

top_sum = sum(grid[0]) # Sum of the first row
bottom_sum = 0 # Tracks Robot2's path through the second row
robo1_req = float('inf') # Initialize to infinity for minimization

for p in range(n):
top_sum -= grid[0][p] # Update the remaining score for Robot2 from the top row

# Robot2's possible scores based on Robot1's current path
robo2_req = max(top_sum, bottom_sum)

# Minimize the score that Robot1 can ensure
robo1_req = min(robo1_req, robo2_req)

# Update the bottom_sum with the current position in the second row
bottom_sum += grid[1][p]

return robo1_req # Return the minimized score for Robot1

risingrohit
Автор

Why my solution is wrong
class Solution:
def gridGame(self, grid: List[List[int]]) -> int:
i=0
j=0
m=2
n=len(grid[0])
arr=[[0 for p in range(n)] for i in range(2)]
arr[0][0]=grid[0][0]
for i in range(m):
for j in range(n):
if(i==0 and j>0):

if(i==1):
if(j==0):

else:
arr[i][j]=max(grid[i][j]+arr[i-1][j], grid[i][j]+arr[i][j-1])
for i in range(m):
print(arr[i])
i=m-1
j=n-1
while i>=0 and j>=0:
arr[i][j]=0
if(i>0 and j>0 and arr[i][j-1]>arr[i-1][j]):
j-=1
elif(i==0):
j-=1
else:
i-=1
sum=0
i=m-1
j=n-1
while i>=0 and j>=0:
sum+=grid[i][j] if arr[i][j]!=0 else 0
if(i>0 and j>0 and arr[i][j-1]>arr[i-1][j]):
j-=1
elif(i==0):
j-=1
else:
i-=1
for i in range(m):
print(arr[i])

return sum

helloim
Автор

If that shows in an interview, i'm leaving

mawhadmd
visit shbcf.ru