Funny Jumping Game

Company: infosys_11oct

Difficulty: medium

Problem Statement

Funny Jumping Game Problem Description You are given a grid of integers with N rows and M columns. Rows are numbered 0 to N-1 from top to bottom and columns are numbered 0 to M-1 from left to right; grid[r][c] is the value in row r , column c . You design a jumping game on this grid. The game starts on any cell (r, c) you like. From the current cell (r, c) you may make one of two kinds of jumps: Down jump: move to a cell (newr, c) in the same column with newr > r , but only if grid[r][c] >= grid[newr][c] . Right jump: move to a cell (r, newc) in the same row with newc > c , but only if grid[r][c] <= grid[r][newc] . A jump may skip over any number of cells; the skipped cells are not visited and their values do not matter. When no jump is possible from the current cell, the game ends. The path of a game is the sequence of cells visited, in the order they were visited, including the starting cell. Let A be the largest number of cells that a path can contain. Let B be the numbe