- DFS, Matrix, TrueGeek, TrueGeek-2021

Minimize count of steps to make all Matrix elements as 0 by replacing neighbours of K with 0

#include using namespace std;  void traverse(int M, int N,              vector& matrix,              int row, int col){          if (row >= 0 && row < M        && col >= 0 && col < N) {        if (matrix[row][col] == 0) {            return;        }                          matrix[row][col] = 0;                  traverse(M, N, matrix, row, col - 1);                  traverse(M, N, matrix, row, col + 1);                  traverse(M, N, matrix, row - 1, col);                  traverse(M, N, matrix, row + 1, col);    }}  void findCount(int M, int N,               vector& matrix,               int K){      int iterations_count = 0;                      for (int row = 0; row < M; row++) {        for (int col = 0; col < N; col++) {            if (K == matrix[row][col]) {                iterations_count++;                traverse(M, N, matrix, row, col);            }        }    }      for (int i = 0; i < M; i++) {        for (int j = 0; j < N; j++) {            if (matrix[i][j] != 0) {                iterations_count = -1;            }        }    }          cout