Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 741393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:37:37+00:00 2026-05-14T08:37:37+00:00

I have the following two dimensional array: static int[,] arr = new int[5, 5]

  • 0

I have the following two dimensional array:

static int[,] arr = new int[5, 5] 
{ 
    { 00, 00, 00, 01, 00 },
    { 00, 00, 01, 01, 00 },
    { 00, 00, 01, 01, 00 },
    { 00, 00, 01, 01, 00 },
    { 00, 00, 00, 01, 00 },
};

I have to a implement a method called Hit(int x, int y). When we hit a 0 in the array (i.e. Hit(0, 0), Hit(1, 1), but not Hit(3, 0)) I would like all the adjacent zeros to the zero we hit to be incremented by 10. So if I call Hit(1, 1), the array should become the following.

static int[,] arr = new int[5, 5] 
{ 
    { 10, 10, 10, 01, 00 },
    { 10, 10, 01, 01, 00 },
    { 10, 10, 01, 01, 00 },
    { 10, 10, 01, 01, 00 },
    { 10, 10, 10, 01, 00 },
};

Any idea how I could implement that? It sounds to me like a Depth First Search/Recursive sort-of algorithm should do the job, but I haven’t been able to implement it for an 2d array.

Thanks for the help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T08:37:38+00:00Added an answer on May 14, 2026 at 8:37 am

    What you are looking for is a Flood fill algorithm, which you can implement in various ways, from DFS (watch the stack) to BFS.

    You can also tighten the code a little bit, but here’s a rough sketch of what I would do (with DFS):

    int[] dx = { 1, 1, 1, 0, 0, -1, -1, -1 };
    int[] dy = { 1, 0, -1, 1, -1, 1, -1, 0 };
    void Hit( int x, int y ) {
        if ( board[x,y] == 0 ) {
            board[x,y] = 10;
            for ( int i = 0; i < 8; i++ ) {
                nx = x + dx[i];
                ny = y + dy[i];
    
                // if nx, ny is in bound
                if ( nx >= 0 && nx < height && ny >= 0 && ny < height )
                    Hit( nx, ny );
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a two-dimensional array. When I print/dump this I get the following My
i have following code for allocation two dimensional array #include <iostream> using namespace std;
Homework: Consider the two-dimensional array A: int A[][] = new int[200][200]; where A[0][0] is
I have the following two dimensional array in my java program. Integer[][] arrayOfSets =
I have a output file which is a two dimensional array (this file was
I have a two dimensional array, i.e. an array of sequences which are also
I have the following two columns: SELECT b.ip_address AS IP ,b.mask AS MASK FROM
Suppose I have the following two strings containing regular expressions. How do I coalesce
I have tried the following two statements: SELECT col FROM db.tbl WHERE col (LIKE
I have parsed XML using both of the following two methods... Parsing the XmlDocument

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.