You are given a matrix A consisting of N rows and M columns, where each cell contains a digit. Your task is to find a continuous sequence of neighbouring cells, starting in the top-left corner and ending in the bottom-right corner (going only down and right), that creates the biggest possible integer by concatenation of digits on the path. By neighbouring cells we mean cells that have exactly one common side.
Write a function:
def solution(A)
that, given matrix A consisting of N rows and M columns, returns a string which represents the sequence of cells that we should pick to obtain the biggest possible integer.
For example, given the following matrix A:
the function should return "997952", because you can obtain such a sequence by choosing a path as shown below:
Write an efficient algorithm for the following assumptions:
- N and M are integers within the range [1..1,000];
- each element of matrix A is an integer within the range [1..9].
Traceback (most recent call last): File "exec.py", line 132, in <module> main() File "exec.py", line 94, in main result = solution( A ) File "/tmp/solution.py", line 10, in solution m[i][j] = int(A[i,j]) TypeError: list indices must be integers or slices, not tuple
Traceback (most recent call last): File "exec.py", line 132, in <module> main() File "exec.py", line 94, in main result = solution( A ) File "/tmp/solution.py", line 10, in solution m[i][j] = int(A[i][j]) NameError: name 'm' is not defined
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m [[0 for rows in range(len(A)] for cols in range(len(A[0])]
for i in range(len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m [[0 for rows in range(len(A)] for cols in range(len(A[0])]
for i in range(len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
pass
Traceback (most recent call last): File "exec.py", line 132, in <module> main() File "exec.py", line 73, in main sol = __import__('solution') File "/tmp/solution.py", line 6 m [[0 for rows in range(len(A)] for cols in range(len(A[0])] ^ SyntaxError: invalid syntax
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m [[0 for rows in range(len(A))] for cols in range(len(A[0])]
for i in range(len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
pass
Traceback (most recent call last): File "exec.py", line 132, in <module> main() File "exec.py", line 73, in main sol = __import__('solution') File "/tmp/solution.py", line 6 m [[0 for rows in range(len(A))] for cols in range(len(A[0])] ^ SyntaxError: invalid syntax
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
for i in range(len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
for i in range(len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
pass
Traceback (most recent call last): File "exec.py", line 132, in <module> main() File "exec.py", line 73, in main sol = __import__('solution') File "/tmp/solution.py", line 6 m [[0 for rows in range(len(A))] for cols in range(len(A[0]))] ^ SyntaxError: invalid syntax
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m [[0 for xin range(len(A))] for cols in range(len(A[0]))]
for i in range(len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m [[0 for x in range(len(A))] for y in range(len(A[0]))]
for i in range(len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
pass
Traceback (most recent call last): File "exec.py", line 132, in <module> main() File "exec.py", line 73, in main sol = __import__('solution') File "/tmp/solution.py", line 6 m [[0 for x in range(len(A))] for y in range(len(A[0]))] ^ SyntaxError: invalid syntax
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m [[0 for x in range(10)] for y in range(10)]
for i in range(len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
pass
Traceback (most recent call last): File "exec.py", line 132, in <module> main() File "exec.py", line 73, in main sol = __import__('solution') File "/tmp/solution.py", line 6 m [[0 for x in range(10)] for y in range(10)] ^ SyntaxError: invalid syntax
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m [[0 for x in range(10)] for y in range())]
for i in range(len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
for i in range(len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
pass
Invalid result type, string expected, <class 'NoneType'> found.
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
m
for i in range(len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
m[0][0] = int(A[0][0]
for i in range(1,len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
for i in range(0,len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
for i in range(0,len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
else:
m[i][j] =
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
for i in range(0,len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
else:
m[i][j] = 10 *
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
for i in range(0,len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
else:
m[i][j] = 10 * int(A[j-2]
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
for i in range(0,len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
else:
m[i][j] = 10 * m[i][j-1] + int(A[j-2]
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
for i in range(0,len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
else:
m[i][j] = 10 * m[i][j-1] + int(A[i][j])
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
for i in range(0,len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
else:
m[i][j] = 10 * m[i][j-1] + int(A[i][j])
else:
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
for i in range(0,len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
else:
m[i][j] = 10 * m[i][j-1] + int(A[i][j])
else:
if j == 0:
m[i][j] = int(A[i][j])
else:
m[i][j] = 10 * m[i][j-1] + int(A[i][j])
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
for i in range(0,len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
else:
m[i][j] = 10 * m[i][j-1] + int(A[i][j])
else:
if j == 0:
m[i][j] = 10 * m[i][j-1] + int(A[i][j])
else:
m[i][j] = 10 * m[i][j-1] + int(A[i][j])
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
for i in range(0,len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
else:
m[i][j] = 10 * m[i][j-1] + int(A[i][j])
else:
if j == 0:
m[i][j] = 10 * m[i-][j] + int(A[i][j])
else:
m[i][j] = 10 * m[i][j-1] + int(A[i][j])
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
for i in range(0,len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
else:
m[i][j] = 10 * m[i][j-1] + int(A[i][j])
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + int(A[i][j])
else:
m[i][j] = 10 * m[i][j-1] + int(A[i][j])
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
for i in range(0,len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
else:
m[i][j] = 10 * m[i][j-1] + int(A[i][j])
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + int(A[i][j])
else:
rowVal =
m[i][j] = 10 * m[i][j-1] + int(A[i][j])
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
for i in range(0,len(A)):
for j in range(len(A[0])):
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
else:
m[i][j] = 10 * m[i][j-1] + int(A[i][j])
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + int(A[i][j])
else:
rowVal = 10 * m[i][j-1] + int(A[i][j])
colVal = 10 * m[i-1][j] + int(A[i][j])
m[i][j] = 10 * m[i][j-1] + int(A[i][j])
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
for i in range(0,len(A)):
for j in range(len(A[0])):
curVal =
if i == 0:
if j == 0:
m[i][j] = int(A[i][j])
else:
m[i][j] = 10 * m[i][j-1] + int(A[i][j])
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + int(A[i][j])
else:
rowVal = 10 * m[i][j-1] + int(A[i][j])
colVal = 10 * m[i-1][j] + int(A[i][j])
m[i][j] = 10 * m[i][j-1] + int(A[i][j])
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
for i in range(0,len(A)):
for j in range(len(A[0])):
curVal = int(A[i][j])
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + int(A[i][j])
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + int(A[i][j])
else:
rowVal = 10 * m[i][j-1] + int(A[i][j])
colVal = 10 * m[i-1][j] + int(A[i][j])
m[i][j] = 10 * m[i][j-1] + int(A[i][j])
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
for i in range(0,len(A)):
for j in range(len(A[0])):
curVal = int(A[i][j])
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + int(A[i][j])
colVal = 10 * m[i-1][j] + int(A[i][j])
m[i][j] = 10 * m[i][j-1] + int(A[i][j])
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
for i in range(0,len(A)):
for j in range(len(A[0])):
curVal = int(A[i][j])
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = 10 * m[i][j-1] + curVal
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
for i in range(0,len(A)):
for j in range(len(A[0])):
curVal = int(A[i][j])
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] =
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
for i in range(0,len(A)):
for j in range(len(A[0])):
curVal = int(A[i][j])
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colval else colVal
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
max
for i in range(0,len(A)):
for j in range(len(A[0])):
curVal = int(A[i][j])
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colval else colVal
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
maxVal = 0
for i in range(0,len(A)):
for j in range(len(A[0])):
curVal = int(A[i][j])
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colval else colVal
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
maxVal = 0
for i in range(0,len(A)):
for j in range(len(A[0])):
curVal = int(A[i][j])
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colval else colVal
maxVal = max(maxVal,
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
maxVal = 0
for i in range(0,len(A)):
for j in range(len(A[0])):
curVal = int(A[i][j])
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colval else colVal
maxVal = max(maxVal,m[i][j])
print("Max val: %d\n" % (maxV))
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
maxVal = 0
for i in range(0,len(A)):
for j in range(len(A[0])):
curVal = int(A[i][j])
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colval else colVal
maxVal = max(maxVal,m[i][j])
print("Max val: %d\n" % (maxVal))
pass
Traceback (most recent call last): File "exec.py", line 132, in <module> main() File "exec.py", line 94, in main result = solution( A ) File "/tmp/solution.py", line 23, in solution m[i][j] = rowVal if rowVal > colval else colVal NameError: name 'colval' is not definedstdout:
Max val: 9 Max val: 99 Max val: 997 Max val: 997
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
maxVal = 0
for i in range(0,len(A)):
for j in range(len(A[0])):
curVal = int(A[i][j])
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colVal else colVal
maxVal = max(maxVal,m[i][j])
print("Max val: %d\n" % (maxVal))
pass
Traceback (most recent call last): File "exec.py", line 132, in <module> main() File "exec.py", line 94, in main result = solution( A ) File "/tmp/solution.py", line 19, in solution m[i][j] = 10 * m[i-1][j] + curVal IndexError: list index out of rangestdout:
Max val: 9 Max val: 99 Max val: 997 Max val: 997 Max val: 997 Max val: 9972 Max val: 9972 Max val: 9979 Max val: 99795
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
maxVal = 0
for i in range(len(A)):
for j in range(len(A[0])):
curVal = int(A[i][j])
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colVal else colVal
maxVal = max(maxVal,m[i][j])
print("Max val: %d\n" % (maxVal))
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
maxVal = 0
for i in range(len(A)):
for j in range(len(A[0])):
curVal = int(A[i][j])
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colVal else colVal
maxVal = max(maxVal,m[i][j])
print("Max val: %d\n" % (maxVal))
pass
Traceback (most recent call last): File "exec.py", line 132, in <module> main() File "exec.py", line 94, in main result = solution( A ) File "/tmp/solution.py", line 19, in solution m[i][j] = 10 * m[i-1][j] + curVal IndexError: list index out of rangestdout:
Max val: 9 Max val: 99 Max val: 997 Max val: 997 Max val: 997 Max val: 9972 Max val: 9972 Max val: 9979 Max val: 99795
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
maxVal = 0
for i in range(len(A)):
for j in range(len(A[0])):
curVal = int(A[i][j])
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colVal else colVal
maxVal = max(maxVal,m[i][j])
print("Max val: %d\n" % (maxVal))
print("Max val: %d\n" % (maxVal))
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
maxVal = 0
for i in range(len(A)):
for j in range(len(A[0])):
curVal = int(A[i][j])
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colVal else colVal
print("max(%d, %d)\n" % (maxVal, m[i][j]))
maxVal = max(maxVal,m[i][j])
print("Max val: %d\n" % (maxVal))
pass
Traceback (most recent call last): File "exec.py", line 132, in <module> main() File "exec.py", line 94, in main result = solution( A ) File "/tmp/solution.py", line 19, in solution m[i][j] = 10 * m[i-1][j] + curVal IndexError: list index out of rangestdout:
max(0, 9) Max val: 9 max(9, 99) Max val: 99 max(99, 997) Max val: 997 max(997, 99) Max val: 997 max(997, 997) Max val: 997 max(997, 9972) Max val: 9972 max(9972, 996) Max val: 9972 max(9972, 9979) Max val: 9979 max(9979, 99795) Max val: 99795
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
maxVal = 0
for i in range(len(A)):
for j in range(len(A[0])):
print("max(%d, %d)\n" % (maxVal))
curVal = int(A[i][j])
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colVal else colVal
print("max(%d, %d)\n" % (maxVal, m[i][j]))
maxVal = max(maxVal,m[i][j])
print("Max val: %d\n" % (maxVal))
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
maxVal = 0
for i in range(len(A)):
for j in range(len(A[0])):
print("m[%d][%d]" % (maxVal))
curVal = int(A[i][j])
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colVal else colVal
print("max(%d, %d)\n" % (maxVal, m[i][j]))
maxVal = max(maxVal,m[i][j])
print("Max val: %d\n" % (maxVal))
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
maxVal = 0
for i in range(len(A)):
for j in range(len(A[0])):
print("m[%d][%d]" % (i, j))
curVal = int(A[i][j])
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colVal else colVal
print("max(%d, %d)\n" % (maxVal, m[i][j]))
maxVal = max(maxVal,m[i][j])
print("Max val: %d\n" % (maxVal))
pass
Traceback (most recent call last): File "exec.py", line 132, in <module> main() File "exec.py", line 94, in main result = solution( A ) File "/tmp/solution.py", line 20, in solution m[i][j] = 10 * m[i-1][j] + curVal IndexError: list index out of rangestdout:
m[0][0] max(0, 9) Max val: 9 m[0][1] max(9, 99) Max val: 99 m[0][2] max(99, 997) Max val: 997 m[1][0] max(997, 99) Max val: 997 m[1][1] max(997, 997) Max val: 997 m[1][2] max(997, 9972) Max val: 9972 m[2][0] max(9972, 996) Max val: 9972 m[2][1] max(9972, 9979) Max val: 9979 m[2][2] max(9979, 99795) Max val: 99795 m[3][0]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
maxVal = 0
for i in range(len(A)):
for j in range():
print("m[%d][%d]" % (i, j))
curVal = int(A[i][j])
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colVal else colVal
print("max(%d, %d)\n" % (maxVal, m[i][j]))
maxVal = max(maxVal,m[i][j])
print("Max val: %d\n" % (maxVal))
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
maxVal = 0
for i in range(len(A[0])):
for j in range(len(A)):
print("m[%d][%d]" % (i, j))
curVal = int(A[i][j])
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colVal else colVal
print("max(%d, %d)\n" % (maxVal, m[i][j]))
maxVal = max(maxVal,m[i][j])
print("Max val: %d\n" % (maxVal))
pass
Traceback (most recent call last): File "exec.py", line 132, in <module> main() File "exec.py", line 94, in main result = solution( A ) File "/tmp/solution.py", line 12, in solution curVal = int(A[i][j]) IndexError: list index out of rangestdout:
m[0][0] max(0, 9) Max val: 9 m[0][1] max(9, 99) Max val: 99 m[0][2] max(99, 997) Max val: 997 m[0][3]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
maxVal = 0
for i in range(len(A)):
for j in range(len(A[0])):
print("m[%d][%d]" % (i, j))
curVal = int(A[i][j])
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colVal else colVal
print("max(%d, %d)\n" % (maxVal, m[i][j]))
maxVal = max(maxVal,m[i][j])
print("Max val: %d\n" % (maxVal))
pass
Traceback (most recent call last): File "exec.py", line 132, in <module> main() File "exec.py", line 94, in main result = solution( A ) File "/tmp/solution.py", line 20, in solution m[i][j] = 10 * m[i-1][j] + curVal IndexError: list index out of rangestdout:
m[0][0] max(0, 9) Max val: 9 m[0][1] max(9, 99) Max val: 99 m[0][2] max(99, 997) Max val: 997 m[1][0] max(997, 99) Max val: 997 m[1][1] max(997, 997) Max val: 997 m[1][2] max(997, 9972) Max val: 9972 m[2][0] max(9972, 996) Max val: 9972 m[2][1] max(9972, 9979) Max val: 9979 m[2][2] max(9979, 99795) Max val: 99795 m[3][0]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
maxVal = 0
for i in range(len(A)):
for j in range(len(A[0])):
print("m[%d][%d]" % (i, j))
print("m[%d][%d]" % (i, j))
curVal = int(A[i][j])
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colVal else colVal
print("max(%d, %d)\n" % (maxVal, m[i][j]))
maxVal = max(maxVal,m[i][j])
print("Max val: %d\n" % (maxVal))
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
maxVal = 0
for i in range(len(A)):
for j in range(len(A[0])):
print("m[%d][%d]" % (i, j))
curVal = int(A[i][j])
print("curVal = %d" % (curVal))
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colVal else colVal
print("max(%d, %d)\n" % (maxVal, m[i][j]))
maxVal = max(maxVal,m[i][j])
print("Max val: %d\n" % (maxVal))
pass
Traceback (most recent call last): File "exec.py", line 132, in <module> main() File "exec.py", line 94, in main result = solution( A ) File "/tmp/solution.py", line 21, in solution m[i][j] = 10 * m[i-1][j] + curVal IndexError: list index out of rangestdout:
m[0][0] curVal = 9 max(0, 9) Max val: 9 m[0][1] curVal = 9 max(9, 99) Max val: 99 m[0][2] curVal = 7 max(99, 997) Max val: 997 m[1][0] curVal = 9 max(997, 99) Max val: 997 m[1][1] curVal = 7 max(997, 997) Max val: 997 m[1][2] curVal = 2 max(997, 9972) Max val: 9972 m[2][0] curVal = 6 max(9972, 996) Max val: 9972 m[2][1] curVal = 9 max(9972, 9979) Max val: 9979 m[2][2] curVal = 5 max(9979, 99795) Max val: 99795 m[3][0] curVal = 9
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
maxVal = 0
for i in range(len(A)):
for j in range(len(A[0])):
print("m[%d][%d]" % (i, j))
curVal = int(A[i][j])
print("curVal = %d" % (curVal))
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
print
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colVal else colVal
print("max(%d, %d)\n" % (maxVal, m[i][j]))
maxVal = max(maxVal,m[i][j])
print("Max val: %d\n" % (maxVal))
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A))] for cols in range(len(A[0]))]
maxVal = 0
for i in range(len(A)):
for j in range(len(A[0])):
print("m[%d][%d]" % (i, j))
curVal = int(A[i][j])
print("curVal = %d" % (curVal))
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
print("here")
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colVal else colVal
print("max(%d, %d)\n" % (maxVal, m[i][j]))
maxVal = max(maxVal,m[i][j])
print("Max val: %d\n" % (maxVal))
pass
Traceback (most recent call last): File "exec.py", line 132, in <module> main() File "exec.py", line 94, in main result = solution( A ) File "/tmp/solution.py", line 22, in solution m[i][j] = 10 * m[i-1][j] + curVal IndexError: list index out of rangestdout:
m[0][0] curVal = 9 max(0, 9) Max val: 9 m[0][1] curVal = 9 max(9, 99) Max val: 99 m[0][2] curVal = 7 max(99, 997) Max val: 997 m[1][0] curVal = 9 here max(997, 99) Max val: 997 m[1][1] curVal = 7 max(997, 997) Max val: 997 m[1][2] curVal = 2 max(997, 9972) Max val: 9972 m[2][0] curVal = 6 here max(9972, 996) Max val: 9972 m[2][1] curVal = 9 max(9972, 9979) Max val: 9979 m[2][2] curVal = 5 max(9979, 99795) Max val: 99795 m[3][0] curVal = 9 here
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A[0))] for cols in range(len(A[0]))]
maxVal = 0
for i in range(len(A)):
for j in range(len(A[0])):
print("m[%d][%d]" % (i, j))
curVal = int(A[i][j])
print("curVal = %d" % (curVal))
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
print("here")
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colVal else colVal
print("max(%d, %d)\n" % (maxVal, m[i][j]))
maxVal = max(maxVal,m[i][j])
print("Max val: %d\n" % (maxVal))
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A[0]))] for cols in range(len(A))]
maxVal = 0
for i in range(len(A)):
for j in range(len(A[0])):
print("m[%d][%d]" % (i, j))
curVal = int(A[i][j])
print("curVal = %d" % (curVal))
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
print("here")
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colVal else colVal
print("max(%d, %d)\n" % (maxVal, m[i][j]))
maxVal = max(maxVal,m[i][j])
print("Max val: %d\n" % (maxVal))
pass
Invalid result type, string expected, <class 'NoneType'> found.stdout:
m[0][0] curVal = 9 max(0, 9) Max val: 9 m[0][1] curVal = 9 max(9, 99) Max val: 99 m[0][2] curVal = 7 max(99, 997) Max val: 997 m[1][0] curVal = 9 here max(997, 99) Max val: 997 m[1][1] curVal = 7 max(997, 997) Max val: 997 m[1][2] curVal = 2 max(997, 9972) Max val: 9972 m[2][0] curVal = 6 here max(9972, 996) Max val: 9972 m[2][1] curVal = 9 max(9972, 9979) Max val: 9979 m[2][2] curVal = 5 max(9979, 99795) Max val: 99795 m[3][0] curVal = 9 here max(99795, 9969) Max val: 99795 m[3][1] curVal = 1 max(99795, 99791) Max val: 99795 m[3][2] curVal = 2 max(99795, 997952) Max val: 997952
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A[0]))] for cols in range(len(A))]
maxVal = 0
for i in range(len(A)):
for j in range(len(A[0])):
print("m[%d][%d]" % (i, j))
curVal = int(A[i][j])
print("curVal = %d" % (curVal))
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
print("here")
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colVal else colVal
print("max(%d, %d)\n" % (maxVal, m[i][j]))
maxVal = max(maxVal,m[i][j])
print("Max val: %d\n" % (maxVal))
return maxVal
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for rows in range(len(A[0]))] for cols in range(len(A))]
maxVal = 0
for i in range(len(A)):
for j in range(len(A[0])):
#print("m[%d][%d]" % (i, j))
curVal = int(A[i][j])
#print("curVal = %d" % (curVal))
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colVal else colVal
maxVal = max(maxVal,m[i][j])
return str(maxVal)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for cols in range(len(A[0]))] for cols in range(len(A))]
maxVal = 0
for i in range(len(A)):
for j in range(len(A[0])):
#print("m[%d][%d]" % (i, j))
curVal = int(A[i][j])
#print("curVal = %d" % (curVal))
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colVal else colVal
maxVal = max(maxVal,m[i][j])
return str(maxVal)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for cols in range(len(A[0]))] for rows in range(len(A))]
maxVal = 0
for i in range(len(A)):
for j in range(len(A[0])):
#print("m[%d][%d]" % (i, j))
curVal = int(A[i][j])
#print("curVal = %d" % (curVal))
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colVal else colVal
maxVal = max(maxVal,m[i][j])
return str(maxVal)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for cols in range(len(A[0]))] for rows in range(len(A))]
maxVal = 0
for i in range(len(A)):
for j in range(len(A[0])):
#print("m[%d][%d]" % (i, j))
curVal = int(A[i][j])
#print("curVal = %d" % (curVal))
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colVal else colVal
maxVal = max(maxVal,m[i][j])
return str(maxVal)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
m = [[0 for cols in range(len(A[0]))] for rows in range(len(A))]
maxVal = 0
for i in range(len(A)):
for j in range(len(A[0])):
#print("m[%d][%d]" % (i, j))
curVal = int(A[i][j])
#print("curVal = %d" % (curVal))
if i == 0:
if j == 0:
m[i][j] = curVal
else:
m[i][j] = 10 * m[i][j-1] + curVal
else:
if j == 0:
m[i][j] = 10 * m[i-1][j] + curVal
else:
rowVal = 10 * m[i][j-1] + curVal
colVal = 10 * m[i-1][j] + curVal
m[i][j] = rowVal if rowVal > colVal else colVal
maxVal = max(maxVal,m[i][j])
return str(maxVal)
The solution obtained perfect score.