Coding Challenge Spotlight: Same Diagonal Stripe Matrix
Recently, I solved a Python-based coding problem published on DataLemur by Nick Singh 📕🐒 — and it was a really interesting one!
Problem
You're given an m x n matrix. Return True if every descending diagonal contains the same number (aka "stripe"). Otherwise, return False.
Python Solution
def has_same_diagonal_stripes(matrix):
if not matrix or not matrix[0]:
return True
m, n = len(matrix), len(matrix[0])
for col in range(n):
val = matrix[0][col]
i, j = 0, col
while i < m and j < n:
if matrix[i][j] != val:
return False
i += 1
j += 1
for row in range(1, m):
val = matrix[row][0]
i, j = row, 0
while i < m and j < n:
if matrix[i][j] != val:
return False
i += 1
j += 1
return True
Why I Liked This Problem:
It’s deceptively simple but requires careful handling of matrix traversal logic.
You explore 2D arrays, edge cases (like empty matrices), and how to process diagonals efficiently.
Great for anyone preparing for data science or software engineering interviews.
Big thanks to Nick Singh 📕🐒 for consistently sharing awesome challenges on DataLemur that make Python learning practical and fun!
If you enjoyed this challenge, try solving it yourself and share your solution! I’d love to see how others approach it.