## Amdocs Interview Question

- 0of 0 votes

AnswerBinu is an aspiring pattern-artist. He spends his free time creating patterns using the computer keyboard. One day, he was creating a random pattern using “/”and “\” characters and during the process, realized that his pattern contained open paths and enclosures (see figure alongside). In this figure, Binu has drawn 6 characters (using either “/” or “\”) each in 4 rows on a standard graph paper. He counted two enclosures (marked with dots), the larger one of 16 squares size and the smaller one of 4 squares size. He also noticed several open paths (non-closed spaces) which are not relevant in the context of this problem. Your task is to help Binu by writing a program that counts all the enclosures in a given pattern and find the size of the largest enclosure. For simplicity, we will not dwell into cases where there are enclosures within enclosures (your code doesn’t need to consider such cases). You may note in the figure that each “/” or “\” is equivalent to 2 units in the graph.

- Master March 29, 2012 in India

Input:-

The input file would contain multiple independent test cases, each test case being a pattern, drawn by Binu. Each test case begins with two integers a and b (1 <= a <= 50, 1 <= b <= 50) where a and b represents the length and breadth of the pattern. The next b lines contain a characters each which are either “/” or “\” (no whitespaces in between). The input ends with a test case having a and b as 0. In the above figure, a = 6, b = 4.

Output:-

For each test case, your code needs to output (on a separate line) two integers x and y (separated by a single whitespace) where x is the total number of enclosures in that pattern and y is the size of the biggest enclosure. In the above figure, the output would be 2 16; meaning, there are 2 enclosures & the size of the largest enclosure is 16 squares. If there are no enclosures in a pattern, you need to output 0 0. If two or more enclosures have the same size (and that happens to be the maximum size), you need to output that size.

EX I/P:

6 4

\//\\/

\///\/

//\\/\

\/\///

3 3

///

\//

\\\

0 0

EX O/P

2 16

0 0

Note:

/\

\/

will have 4 diamond shape squares in it. They have given a image. not able to add it here.| Report Duplicate | Flag | PURGE

Amdocs C

**Country:**India

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

the no.of enclosures in fisrt example must be 3.

- Mounika March 29, 2012