AlgoUniversity
  • Go Back
Discussion
Grid Path :

Author

hardik kapoor

Difficulty Level : Medium

Submissions : 241

Asked In : Qualcomm

Marks :10

: 1 | : 0

Given a grid with N rows and M columns, consisting of the following symbols:

  • '#' represents obstacle
  • '.' represents path
  • 'S' represents starting point
  • 'E' represents ending point

You cannot travel through obstacles, and consider only the cells sharing an edge to be adjacent. (4 - adjacency)

Please tell if there exists a path from 'S' to 'E' following the above conditions.

Input

First line contains 2 space separated integers N (1 <= N <= 1e5) and M (1 <= M <= 1e5), N*M <= 1e6.

Next N lines contains string of M length consisting of characters '#', '.', 'S' and 'E'.

There exists exactly one 'S' and 'E' in the grid.

Output

Output "YES" if the path exists, "NO" if the path doesn't exist.

Examples

Input
5 5
#..#.
S#..#
....#
#.#E#
#####
Output
YES
Input
5 5
#..#.
S#..#
...##
#.#E#
#####
Output
NO

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.