Question: Please solve the following in Java only Lucy loves to play the Hop, Skip and Jump game. Given an N * M matrix and starting
Please solve the following in Java only
Lucy loves to play the Hop, Skip and Jump
game. Given an NM matrix and starting from
cell 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 anticlockwise
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 spaceseparated
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.
Output
Explanation:
Lucy starts with skips hops onto skip
hops onto skips hops onto skips
and finally hops onto
So the output is
Code in java
matrix, represents the elements in each cell of the matrix of size NM
def funcHopSkipJumpmatrix:
# Write your code here
return
def main:
# input for matrix
matrix
matrixrows, matrixcols mapint rawinputsplit
for idx in rangematrixrows:
matrix.appendlistmapint rawinputsplit
result funcHopSkipJumpmatrix
print result,
if namemain:
main
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
