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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started