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 8301869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:08:58+00:00 2026-06-08T17:08:58+00:00

This is an interview question: given a boolean matrix find the size of the

  • 0

This is an interview question: given a boolean matrix find the size of the largest contiguous square sub-matrix, which contains only “true” elements.

I found this question on SO but did not understand the answer. The proposed algorithm moves a diagonal line from the left top to the right bottom and keeps track of the rectangles of “true” elements as the line goes.

My questions:

  • How to keep track of the rectangles in the algorithm?
  • Why do we move the diagonal line? What if we move a vertical/horizontal line or both?
  • How to calculate the algorithm complexity?
  • 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-06-08T17:08:59+00:00Added an answer on June 8, 2026 at 5:08 pm

    I can’t understand the answer in the link you posted, and I don’t think the complexity given there is optimal for your problem. (It claim that there is an O(N^(3/2)*logN) algorithm where N=n*n is the number of elements in the original matrix.)

    For your largest square sub-matrix problem, there is a DP algorithm whose complexity is linear with the number of elements:

    Let the original matrix is A[n][n], we are trying to find a matrix B[n][n], where B[i][j] indicates the size of largest square sub-matrix whose bottom-right element is A[i][j]. So

    for (i = 0 ; i < n ; ++i)
      for (j = 0 ; j < n ; ++j) 
        if (A[i][j] == 0) B[i][j] = 0;
        else {
          if (B[i-1][j] != B[i][j-1]) {
            B[i][j] = min(B[i-1][j], B[i][j-1]) + 1
          } else {
            if (A[i-B[i-1][j]][j-B[i-1][j]] == 1)
              B[i][j] = B[i-1][j] + 1;
            else
              B[i][j] = B[i-1][j];
          }
        }
    

    And the largest B[i][j] is the answer.

    p.s. I didn’t check the array range for simplification. You can just consider the out-of-range elements are zero.

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

Sidebar

Related Questions

This is an interview question. Given a number of strings find such strings, which
I was asked this question during phone interview. Given two strings find the minimal
I came across this post , which reports the following interview question: Given two
this is a google interview question : Given a N*N Matrix. All rows are
This is an interview question: Given a string, find all its permutations that are
This was an interview question: Given an amount, say $167.37 find all the possible
This is an interview question : Given a directory with lots of files, find
This is an interview question I faced recently. Given an array of 1 and
This is an interview question. I have K machines each of which is connected
This is probably a Microsoft interview question. Find the kth smallest element (ignoring duplicates)

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.