Menu
Coddy logo textTech

TV

Lesson 29 of 32 in Coddy's Coding Problems course.

challenge icon

Challenge

Hard

A TV is drawn using numbers like below:

    1 1 1 1 1 1 1 1 1
    1 2 2 2 2 2 2 2 1
    1 2 2 2 2 2 2 2 1
    1 2 2 2 2 2 2 2 1
    1 1 1 1 1 1 1 1 3

With ones is represented the border of the TV, with twos the actual screen and the three in the lower right corner is the power button.

 

You are given a sequence of numbers from input until a 3 is entered. Calculate the width and height of the TV and output it to the screen.

 

Input
1 1 1 1 1 1 1 1 1
1 2 2 2 2 2 2 2 1
1 2 2 2 2 2 2 2 1
1 2 2 2 2 2 2 2 1
1 1 1 1 1 1 1 1 3

Output
5 9

Input
1 1 1
1 2 1
1 1 3

Output
3 3

Try it yourself

#include <stdio.h>

int main() {
    // Write code here
    return 0;
}

All lessons in Coding Problems