Question: Problem Statement: Stanley the Slithery Snake loves to eat apples! Given an m x n grid with some apples, he wants to know when he

Problem Statement: Stanley the Slithery Snake loves to eat apples! Given an m x n grid with some apples, he wants to know when he would eat each apple. The m x n grid consists of dots ('.'), which denote empty spaces, and apples ('X'). Stanley slithers in a spiral direction, starting from the top left of the grid moving rightwards, and then spiralling in a clockwise direction once he hits the end of the grid, or hits a place he has travelled before. Given an m x n grid, output all the apples he ate, in order of his moves. Also, you have to specify the coordinates of the ith apple he ate at his ith step, in this format: Apple at (X, Y) eaten at step i Input: Two integers m and n in a single line. 1 <= m, n <= 1000 There will be m lines after, each line containing a string of length n. The string consists of only dots ('.') or apples ('X'). It is guaranteed that the grid consists of at least 1 apple. Output: All the apples that Stanley ate, in order of his moves, in this format: Apple at (X, Y) eaten at step i Each statement should be on a single line. Example: Input: 4 4 .... .X.. .... .... Output: Apple at (1, 1) eaten at step 13

the coding language is java

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!