Click here to Skip to main content
13,800,574 members
Rate this:
 
Please Sign up or sign in to vote.
i have a question in java
The question :

given an 2d array of integer

find the biggest rectangle of the same value

example :

2 , 2 , 2

2 , 2 , 1

1 , 1 , 2

the answer will be : 4 because the biggest rectangle is

2 , 2

2 , 2

i cant make a program in java to solve it

so please if someone know how to solve it in java or

can give me a way to do it please comment

What I have tried:

i tired to write a code but
it not working:
the code:
public class thefinish { 
    static int max(int [][]a) 
    { 
        int result = 0; 
        int sum1 = -1;
        for(int i=0; i<a.length; i++) {
        	for(int j=0; j<a[i].length; j++) {
        		sum1= 0;
        			for(int k=0; k<a.length; k++) {
        				for(int l=0; l<a[k].length; l++) {
        					if(a[i][j]==a[k][l]) {
        						while(a[i][j]==a[k][l] && l!=a[k].length-1) {
        						sum1++;
        						l++;
        						}
        					}
        					else {
        					    sum1=0;
        					}
        					if(sum1>result) {
        						result = sum1;
        					}
        					
        				}
        			}
        	}
        }
        		System.out.println(result);
        		return result; 
    		} 
    public static void main(String[] args) {
   	 int [][]a={ 	{0, 0, 0, 0, 9, 0}, 
                    {0, 8, 9, 9, 0, 0}, 
                    {0, 8, 9, 0, 0, 0}, 
                    {0, 8, 0, 0, 0, 0}, 
                    {9, 0, 0, 0, 0, 0}, 
                    {0 ,0, 0, 0, 0, 0},}; 
   	 max(a); 

   	}
}
Posted 6-Dec-18 10:33am
Updated 6-Dec-18 10:55am
v2
Comments
ZurdoDev 6-Dec-18 16:52pm
   
You need to explain where you are stuck. No one is going to do all of your homework for you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web06 | 2.8.181215.1 | Last Updated 6 Dec 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100