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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:04:33+00:00 2026-06-12T20:04:33+00:00

Well here is an interesting problem. Suppose I have a table on an sql

  • 0

Well here is an interesting problem. Suppose I have a table on an sql db filled with x,y coordinates (positive quadrant) and each having a color value i.e. the schema looks like <x , y, color>. The task is to detect the largest possible square with the same color. Ive been trying to solve this problem for hours and cant seem to make a dent in it.

I’m not looking for a solution but rather hints.

Note that this all has to happen in SQL mainly using various joins, grouping and aggregate operations. Some sample code would be nice.

  • 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-12T20:04:33+00:00Added an answer on June 12, 2026 at 8:04 pm

    If you only request the corners be the same color, you could do

    top left corner
    join top right corner on equal x and color and greater y
    join bottom left corner on equal y and color and greater x
    join bottom right on equal x, y and color
    order by (x1-x2)*(y1-x2) descending
    limit 1
    

    Of course, the limit 1 won`t have much effect on performance because it will have to generate all squares anyways.

    You can (greatly) improve the speed by adding the (color,x,y) and (color,y,x) indexes.
    The execution plan will most likely end up:

    (1) full scan for all top left corners
    (2) dependent index scan for all top right corners
    (3) dependent index scan for all bottom left corners
    (4) dependent index scan for the bottom right corner expecting at most one match
    (5) (partial) table sort of the entire set of squares (cannot use indexes)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is one very interesting problem. I am using SQL Server 2008. I have
Well, here is my problem: I have an application that uses a custom Javascript
Here's an interesting one... hope I can explain it well... I have a collection
Well i need some help here i don't know how to solve this problem.
Here is my code (well, some of it). The question I have is, can
Well, here is what I wanna do: I have a text field and a
Here is an interesting optimization problem that I think about for some days now:
I am having a problem with the get_post method. Here is my code: <!DOCTYPE
I am using ASP .NET MVC 3 and I have an interesting problem to
Here is the problem: I have many sets of points, and want to come

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.