AlgoUniversity
  • Go Back
Discussion
Unique Paths :

Author

Ujjwal Srivastava

Difficulty Level : Easy

Submissions : 306

Asked In : Amazon

Marks :10

: 3 | : 0

You are given an $$$m$$$ x $$$n$$$ integer array grid. There is a robot initially located at the top-left corner $$$(i.e., grid[0][0])$$$. The robot tries to move to the bottom-right corner $$$(i.e., grid[m - 1][n - 1])$$$. The robot can only move either down or right at any point in time.

An obstacle and space are marked as $$$1$$$ or $$$0$$$ respectively in the grid. A path that the robot takes cannot include any square that is an obstacle.

Return the number of possible unique paths that the robot can take to reach the bottom-right corner. Since answer may be large output answer modulo $$$998244353.$$$

Input

The first line contains two space-separated integers $$$m$$$ and $$$n$$$ the number of rows and columns respectively. The next $$$m$$$ lines contain $$$n$$$ spaced separated integers $$$0$$$ or $$$1$$$.$$$(1 \le m, n \le 100).$$$

Output

The number of possible unique paths that the robot can take to reach the bottom-right corner modulo $$$998244353.$$$

Examples

Input
2 3
0 0 0
0 0 0
Output
3
Input
4 5
0 0 0 0 0
0 1 1 1 1
0 0 1 0 1
0 0 0 1 0
Output
0
Input
3 9
0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0
0 1 1 0 0 0 0 0 0
Output
27

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.