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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:04:14+00:00 2026-05-14T06:04:14+00:00

I have a small program to do in Java. I have a 2D array

  • 0

I have a small program to do in Java. I have a 2D array filled with 0 and 1, and I must find the largest rhombus (as in square rotated by 45 degrees) and their numbers.

Example:

0 1 0 0 0 1

1 0 1 1 1 0

1 0 1 1 1 1

0 1 1 1 1 1

0 0 1 1 1 1

1 1 1 1 1 1

Result:

      1    

    1 1 1  

  1 1 1 1 1

    1 1 1  

      1    

The problem is similar to this SO question.

If you have any idea, post it 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-14T06:04:14+00:00Added an answer on May 14, 2026 at 6:04 am

    This too long for a comment. I’ll post my solution later on if you can’t solve it but here’s how I’ve done it (in less than 15 lines of code): I first created a second array (a little big bigger [n+2][n+2]) and did n/2 pass:

    0 0 0 0 0 0 0 0 
    0 0 1 0 0 0 1 0 
    0 1 0 1 1 1 0 0 
    0 1 0 1 2 2 1 0 
    0 0 1 2 2 2 1 0 
    0 0 0 1 2 2 1 0 
    0 1 1 1 1 1 1 0 
    0 0 0 0 0 0 0 0 
    
    0 0 0 0 0 0 0 0 
    0 0 1 0 0 0 1 0 
    0 1 0 1 1 1 0 0 
    0 1 0 1 2 2 1 0 
    0 0 1 2 3 2 1 0 
    0 0 0 1 2 2 1 0 
    0 1 1 1 1 1 1 0 
    0 0 0 0 0 0 0 0
    

    Where a non-zero number x means “I’m the center of a rhombus of size x” (I’m expressing the size in relation with the length of the diagonals [which are both equal in your case] of the rhombus). You can find if you have the center of a rhombus of size (k+1) by checking if {top,right,down,left} are all the centers of rhombus of size k.

    The advantage of first creating a bigger array is that it really simplifies your logic but I could do it in place, with a more convoluted logic, by modifying the original array or by using a second array of the same size as the input (once again, it’s way easier to simply put a safe “fence” of all-zeroes around your input).

    If you don’t “surround” your array with a fence, you have a lot of additional if/else checks: this would be prone to errors, lead to bigger code and lead to uglier code.

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

Sidebar

Related Questions

I have a small Java program that reads list of IPs from text file
I have a small java program that reads a file in, in eclipse i
I have a Java program that runs many small simulations. It runs a genetic
I'm working on a program in Java and I have run into a small
Java. I have a very small int array (4 elements). What's the fastest way
I have a small java program that searches the contents of all *.txt files
As a Christmas gift I have written a small program in Java to calculate
I made this small Java program using eclipse IDE. I have set the workspace
I have a small Java program that uses ImageIcons on JLabels to display pictures.
I currently have a small Java program which I would like to run both

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.