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

  • SEARCH
  • Home
  • 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 4584132
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:18:43+00:00 2026-05-21T21:18:43+00:00

I need an algorithm which can parse a 2D array and return the largest

  • 0

I need an algorithm which can parse a 2D array and return the largest continuous rectangle. For reference, look at the image I made demonstrating my question.

enter image description here

  • 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-21T21:18:44+00:00Added an answer on May 21, 2026 at 9:18 pm

    Generally you solve these sorts of problems using what are called scan line algorithms. They examine the data one row (or scan line) at a time building up the answer you are looking for, in your case candidate rectangles.

    Here’s a rough outline of how it would work.

    Number all the rows in your image from 0..6, I’ll work from the bottom up.

    Examining row 0 you have the beginnings of two rectangles (I am assuming you are only interested in the black square). I’ll refer to rectangles using (x, y, width, height). The two active rectangles are (1,0,2,1) and (4,0,6,1). You add these to a list of active rectangles. This list is sorted by increasing x coordinate.

    You are now done with scan line 0, so you increment your scan line.

    Examining row 1 you work along the row seeing if you have any of the following:

    • new active rectangles
    • space for existing rectangles to grow
    • obstacles which split existing rectangles
    • obstacles which require you to remove a rectangle from the active list

    As you work along the row you will see that you have a new active rect (0,1,8,1), we can grow one of existing active ones to (1,0,2,2) and we need to remove the active (4,0,6,1) replacing it with two narrower ones. We need to remember this one. It is the largest we have seen to far. It is replaced with two new active ones: (4,0,4,2) and (9,0,1,2)

    So at the send of scan line 1 we have:

    • Active List: (0,1,8,1), (1,0,2,2), (4,0,4,2), (9, 0, 1, 2)
    • Biggest so far: (4,0,6,1)

    You continue in this manner until you run out of scan lines.

    The tricky part is coding up the routine that runs along the scan line updating the active list. If you do it correctly you will consider each pixel only once.

    Hope this helps. It is a little tricky to describe.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need an algorithm to determine if a sentence, paragraph or article is negative
I need a quick algorithm to select 5 random elements from a generic list.
I need the perfect algorithm or C# function to calculate the difference (distance) between
I need an example algorithm that will draw pixels one at a time on
When I need some complex algorithm I first check if there's anything relevant already
A friend was in need of an algorithm that would let him loop through
For a random event generator I'm writing I need a simple algorithm to generate
I need some help regarding algorithm for randomness. So Problem is. There are 50
I need a reasonably smart algorithm to come up with nice grid lines for
I need a binary search algorithm that is compatible with the C++ STL containers,

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.