Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6379 |

@blackshadows | 6329 |

@mb1973 | 5358 |

@Quandray | 5231 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3357 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@ritiksethi21 | 1050 |

@aroranayan999 | 807 |

@RizulBansal | 685 |

@ashishtrehan002 | 538 |

@hemantgarg923 | 528 |

@simrangoyal | 526 |

@ronaldo77 | 520 |

@thanosagain | 505 |

@anishrajan | 505 |

@ssparteek470 | 495 |

@rahul2312 | 491 |

Complete Leaderboard |

A Toeplitz (or diagonal-constant) matrix is a matrix in which each descending diagonal from left to right is constant, i.e., all elements in a diagonal are same.

Given a matrix A of order N X M your task is to complete the function **isToeplitz** which returns true if the matrix is Toeplitz otherwise returns false.

**Input:**

The first line of input contains an integer T denoting the no of test cases .Then T test cases follow . Each test case contains two lines. The first line of each test case contains two integers N and M denoting the order of the matrix . Then in the next line are N*M space separated values of the matrix.

**Output:**

The output for each test case will be 1 if the matrix is Toeplitz else it will be 0.

**Constraints:**

1<=T<=50

1<=N,M<=40

1<=A[][]<=100

**Example(To be used only for expected output):
Input**

2

3 3

6 7 8 4 6 7 1 4 6

2 3

1 2 3 4 5 6

1

0

(i) The first test case represents a 3x3 matrix which looks like

6 7 8

4 6 7

1 4 6

Output: 1(True) as values in all diagonals are same.

(ii) In second test case matrix of order 2x3 will be

1 2 3

4 5 6

Output: 0(False) as values in all diagonals are not same.

Note:The

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Toeplitz matrix

...