class Solution:
def calculateMinimumHP(self, dungeon: List[List[int]]) -> int:
def oneIfNotPos(a):
return a if a > 0 else 1
def f(i: int, j: int) -> int:
cached = self.cache.get((i, j))
if cached:
return cached
answer = min(oneIfNotPos(f(i, j + 1) - dungeon[i][j]), \
oneIfNotPos(f(i + 1, j) - dungeon[i][j]))
self.cache[(i, j)] = answer
return answer
m = len(dungeon)
n = len(dungeon[0])
# init cache to remove ifs from f
self.cache = {(m - 1, n - 1): oneIfNotPos(1 - dungeon[m - 1][n - 1])}
for i in range(0, m):
self.cache[(i, n)] = 1000 000000 # inf
for j in range(0, n):
self.cache[(m, j)] = 10000 00000 # inf
return f(0, 0)
Python
Dungeon Hunters
Telegram -https://t.me/Coding_solution_0
def calculateMinimumHP(self, dungeon: List[List[int]]) -> int:
def oneIfNotPos(a):
return a if a > 0 else 1
def f(i: int, j: int) -> int:
cached = self.cache.get((i, j))
if cached:
return cached
answer = min(oneIfNotPos(f(i, j + 1) - dungeon[i][j]), \
oneIfNotPos(f(i + 1, j) - dungeon[i][j]))
self.cache[(i, j)] = answer
return answer
m = len(dungeon)
n = len(dungeon[0])
# init cache to remove ifs from f
self.cache = {(m - 1, n - 1): oneIfNotPos(1 - dungeon[m - 1][n - 1])}
for i in range(0, m):
self.cache[(i, n)] = 1000 000000 # inf
for j in range(0, n):
self.cache[(m, j)] = 10000 00000 # inf
return f(0, 0)
Python
Dungeon Hunters
Telegram -https://t.me/Coding_solution_0
Forwarded from Off Campus Job Update
class Solution:
def calculateMinimumHP(self, dungeon: List[List[int]]) -> int:
def oneIfNotPos(a):
return a if a > 0 else 1
def f(i: int, j: int) -> int:
cached = self.cache.get((i, j))
if cached:
return cached
answer = min(oneIfNotPos(f(i, j + 1) - dungeon[i][j]), \
oneIfNotPos(f(i + 1, j) - dungeon[i][j]))
self.cache[(i, j)] = answer
return answer
m = len(dungeon)
n = len(dungeon[0])
# init cache to remove ifs from f
self.cache = {(m - 1, n - 1): oneIfNotPos(1 - dungeon[m - 1][n - 1])}
for i in range(0, m):
self.cache[(i, n)] = 1000 000000 # inf
for j in range(0, n):
self.cache[(m, j)] = 10000 00000 # inf
return f(0, 0)
Python
Dungeon Hunters
Telegram -https://t.me/Coding_solution_0
def calculateMinimumHP(self, dungeon: List[List[int]]) -> int:
def oneIfNotPos(a):
return a if a > 0 else 1
def f(i: int, j: int) -> int:
cached = self.cache.get((i, j))
if cached:
return cached
answer = min(oneIfNotPos(f(i, j + 1) - dungeon[i][j]), \
oneIfNotPos(f(i + 1, j) - dungeon[i][j]))
self.cache[(i, j)] = answer
return answer
m = len(dungeon)
n = len(dungeon[0])
# init cache to remove ifs from f
self.cache = {(m - 1, n - 1): oneIfNotPos(1 - dungeon[m - 1][n - 1])}
for i in range(0, m):
self.cache[(i, n)] = 1000 000000 # inf
for j in range(0, n):
self.cache[(m, j)] = 10000 00000 # inf
return f(0, 0)
Python
Dungeon Hunters
Telegram -https://t.me/Coding_solution_0
Tcs coding
1.D
2.break
3.arrayindexout
4.B
5.B
6.D
7.change control
Telegram -https://t.me/Coding_solution_0
1.D
2.break
3.arrayindexout
4.B
5.B
6.D
7.change control
Telegram -https://t.me/Coding_solution_0
Tcs coding
1.D
2.break
3.arrayindexout
4.B
5.B
6.D
7.change control
8.37
Telegram - https://t.me/Coding_solution_0
1.D
2.break
3.arrayindexout
4.B
5.B
6.D
7.change control
8.37
Telegram - https://t.me/Coding_solution_0
Tcs coding
1.D
2.break
3.arrayindexout
4.B
5.B
6.D
7.change control
8-37
9-10
10-2
Telegram - https://t.me/Coding_solution_0
1.D
2.break
3.arrayindexout
4.B
5.B
6.D
7.change control
8-37
9-10
10-2
Telegram - https://t.me/Coding_solution_0
โ
Working with codes
โ Guys if you cant send messages in discussion group
Join this the problem will resolve
https://t.me/company_0
https://t.me/company_0
https://t.me/company_0
โ Guys if you cant send messages in discussion group
Join this the problem will resolve
https://t.me/company_0
https://t.me/company_0
https://t.me/company_0
max_li=[]
def longest_subarray(arr, d):
(i, j, e) = (0, 1, 0)
for i in range(d - 1):
if arr[i] == arr[i + 1]:
j += 1
else:
j = 1
if e < j:
e = j
return e
temp=li.copy()
for each in li:
max_li.append(longest_subarray(temp, len(temp)))
temp=li.copy()
while(True):
try:
temp.remove(each)
except:
break
print(max(max_li))
Python
Ali army
Telegram-
https://t.me/Coding_solution_0
def longest_subarray(arr, d):
(i, j, e) = (0, 1, 0)
for i in range(d - 1):
if arr[i] == arr[i + 1]:
j += 1
else:
j = 1
if e < j:
e = j
return e
temp=li.copy()
for each in li:
max_li.append(longest_subarray(temp, len(temp)))
temp=li.copy()
while(True):
try:
temp.remove(each)
except:
break
print(max(max_li))
Python
Ali army
Telegram-
https://t.me/Coding_solution_0
INFOSYS EXAM ALL SLOTS SOLUTION GROUP ๐
Telegram - https://t.me/Coding_solution_0
Telegram - GROUP
https://t.me/good_coders
โ Share post in ur college Whatsapp grps.
Telegram - https://t.me/Coding_solution_0
Telegram - GROUP
https://t.me/good_coders
โ Share post in ur college Whatsapp grps.
perfect_sum(arr, s, result) :
x = [0]*len(arr)
j = len(arr) - 1
while (s > 0) :
x[j] = s % 2
s = s // 2
j -= 1
sum = 0
for i in range(len(arr)) :
if (x[i] == 1) :
sum += arr[i]
if (sum == result) :
print("{",end="");
for i in range(len(arr)) :
if (x[i] == 1) :
print(arr[i],end= ", ");
print("}, ",end="")
def print_subset(arr, K) :
x = pow(2, len(arr))
for i in range(1, x):
perfect_sum(arr, i, K)
# Driver code
arr = [ ]
n = int(input("Enter length of array : "))
s=int(input("Enter sum : "))
for i in range(n):
ele=int(input("Enter element : "))
arr.append(ele)
print_subset(arr, s)
array AR of size N
Telegram - https://t.me/Coding_solution_0
x = [0]*len(arr)
j = len(arr) - 1
while (s > 0) :
x[j] = s % 2
s = s // 2
j -= 1
sum = 0
for i in range(len(arr)) :
if (x[i] == 1) :
sum += arr[i]
if (sum == result) :
print("{",end="");
for i in range(len(arr)) :
if (x[i] == 1) :
print(arr[i],end= ", ");
print("}, ",end="")
def print_subset(arr, K) :
x = pow(2, len(arr))
for i in range(1, x):
perfect_sum(arr, i, K)
# Driver code
arr = [ ]
n = int(input("Enter length of array : "))
s=int(input("Enter sum : "))
for i in range(n):
ele=int(input("Enter element : "))
arr.append(ele)
print_subset(arr, s)
array AR of size N
Telegram - https://t.me/Coding_solution_0