Git Product home page Git Product logo

sinc_2's Introduction

Given a 2 dimensional array AxB of any size as input.
Implement a solution to flip all islands of 0’s to 1’s and display the result
An island is defined as any region of one or more connected 0’s, 
surrounded by 1’s on all FOUR sides (Up, Down, Left and Right). 

Example input and output as follows:

Input 1    0utput 1
[1,1,0,1]  [1,1,0,1]
[1,1,0,1]  [1,1,0,1]
[1,0,1,1]  [1,1,1,1]
[1,1,1,1]  [1,1,1,1]

Input 2   0utput 2
[1,1,1,1]  [1,1,1,1]
[1,1,0,1]  [1,1,1,1]
[1,0,0,1]  [1,1,1,1]
[1,1,1,1]  [1,1,1,1]

Input 3   0utput 3
[1,1,0,1]  [1,1,0,1]
[1,0,0,1]  [1,0,0,1]
[1,0,1,1]  [1,0,1,1]
[1,1,1,1]  [1,1,1,1]

This will have a time complexity of N x K. In the worst case, we have to iterate over every N cell in the world and 
for each world cell, we then have to check K world cells at that point to fill the island. 
Space complexity is 3N -> N for holding the visited cells, our stack holding the current cells to check and the areas to paint.  

input
1101
1101
1011
1111
---------------------------
output
1101
1101
1111
1111
---------------------------
input
1111
1101
1001
1111
---------------------------
output
1111
1111
1111
1111
---------------------------
input
1101
1001
1011
1111
---------------------------
output
1101
1001
1011
1111
---------------------------
input
110111111111
100100010110
101101001001
011011001011
111001011011
111011111011
---------------------------
output
110111111111
100111111110
101111111001
011011111011
111001111011
111011111011
---------------------------

Process finished with exit code 0

sinc_2's People

Contributors

kishisaka avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.