16.6k views
1 vote
Please solve the following in Python or Java only

Lucy loves to play the Hop, Skip and Jump
game. Given an N*M matrix and starting from
cell (1,1), her challenge is to hop in an anti-
clockwise direction and skip alternate cells. The
goal is to find out the last cell she would hop
onto.
Write an algorithm to find the last cell Lucy
would hop onto after moving anti-clockwise
and skipping alternate cells.
Input
The first line of input consists of two integers-
matrix_ row and matrix_ col, representing the
number of rows (N) and the number of
columns (M) in the matrix, respectively.
The next M lines consist of N space-separated
integers representing the elements in each cell
of the matrix,
Output
Print an integer representing the last cell Lucy
would hop onto after following the given
instructions.
Example
Input.
3 3
29 3 37
15 41 3
1 10 14
Output
41
Explanation:
Lucy starts with 29, skips 15, hops onto 1, skip
10, hops onto 14, skips 3, hops onto 37, skips 8
and finally hops onto 41
So, the output is 41
Code in python
"""
matrix, represents the elements in each cell of the matrix of size N*M.
"""
def funcHopSkipJump(matrix):
# Write your code here
return
def main():
# input for matrix
matrix = []
matrix_rows, matrix_cols = map(int, raw_input().split())
for idx in range(matrix_rows):
matrix.append(list(map(int, raw_input().split())))
result = funcHopSkipJump(matrix)
print result,
if __name__ == "__main__":
main()

1 Answer

4 votes

Answer:

"""

matrix, represents the elements in each cell of the matrix of size N*M.

"""

def funcHopSkipJump(matrix):

# Write your code here

return

def main():

#input for matrix

matrix = []

matrix_rows,matrix_cols = map(int, input().split())

for idx in range(matrix_rows):

matrix.append(list(map(int, input().split())))

result = funcHopSkipJump(matrix)

print(result)

if __name__ == "__main__":

main()

Step-by-step explanation:

"""

matrix, represents the elements in each cell of the matrix of size N*M.

"""

def funcHopSkipJump(matrix):

# Write your code here

return

def main():

#input for matrix

matrix = []

matrix_rows,matrix_cols = map(int, input().split())

for idx in range(matrix_rows):

matrix.append(list(map(int, input().split())))

result = funcHopSkipJump(matrix)

print(result)

if __name__ == "__main__":

main()

User X A
by
7.3k points