C++ code to check given flag is stripped or not

Suppose we have a matrix of size n x m. Each cell will hold one value from 0 to 9. There is a flag should be striped: each horizontal row of the flag should contain squares of the same color, and the colors of the adjacent horizontal rows should be different. We have to check given matrix is valid flag or not.

So, if the input is like

0 0 0
1 1 1
3 3 3

Steps

To solve this, we will follow these steps −

n := row count of matrix
m := column count of matrix
l := 'm'
res := 1
for initialize i := 0, when i 

Example

Let us see the following implementation to get better understanding −

#include 
using namespace std;
bool solve(vector> matrix){
   int n = matrix.size();
   int m = matrix[0].size();
   char l = 'm';
   bool res = 1;
   for (int i = 0; i > matrix = { { 0, 0, 0 }, { 1, 1, 1 }, { 3, 3, 3 } };
   cout 

Input

{ { 0, 0, 0 }, { 1, 1, 1 }, { 3, 3, 3 } }

Output

1
Updated on: 2022-03-29T11:53:56+05:30

337 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements