# [SOLUTION] Flower Sequence solution codechef 2021

## Flower Sequence solution codechef

Table of Contents

There is a square garden with red and white flowers planted. Unnati enters the garden from the top left corner and she travels in a spiral inwards manner and plucks all the flowers. We need to find the longest sequence of red and white flowers plucked by Unnati in this process. We can represent the garden in the for of a square matrix. Each element in the matrix is a flower. Red flowers are denoted by 1 and white flowers by 0.

• TravelDirectionTravelDirection–
• 1clockwise1–clockwise
• 2anticlockwise2–anticlockwise

### Input: Flower Sequence solution codechef

-First Line will contain 3 space separated integers denoting r, c, direction. -Next r lines we will have c space separated integers representing the matrix. .

### Output: Flower Sequence solution codechef

-Two space separated integers X and Y. X- Longest Sequence of Red flowers Y- Longest sequence of White Flowers

### Constraints : Flower Sequence solution codechef

• 1r10001≤r≤1000
• 1c10001≤c≤1000
• Direction1or2Direction–1or2

### Sample Input: Flower Sequence solution codechef

4 4 1
1 1 0 1
0 1 0 1
1 0 1 1
0 0 1 1


5 2

### EXPLANATION:

• The sequence of traversal is (0,0) > (0,1) > (0,2)> (0,3) > (1,3) > (2,3) > (3,3)> (3,2) > (3,1) > (3,0) > (2,0)> (1,0) > (1,1) > (1,2) > (2,2)> (2,1)
• Longest Red flower Sequence – (0,3) > (1,3) > (2,3) > (3,3)> (3,2)
• Longest White Flower Sequence – (3,1) > (3,0)