Replace 0's

Given a matrix where every element is either 1 or 0(zero), replace 0 with 1 if surrounded by 1. A 0 (or a set of 0s) is considered to be surrounded by 1 if there are 1 at locations just below, just above, just left and just right of it.

See the sample input.

Input format :
Line 1: Number of rows M and cols N in the matrix
Line 2: MXN elements of the matrix separated by space 
Output Format :
Just make the changes if any, no need to print or return the matrix.
Constraints :
1 <= M <= 10^2
1 <= N <= 10^2
CodingNinjas
author
2y
Space Complexity: O(1)Explanation: Time Complexity: O(1)Explanation:
Help your peers!
Add answer anonymously...
Spring Time Software Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter