My input is a 2D jagged array, it contains some rows of variable lengths. I'd like to convert it into a list of 2D rectangular non overlapping arrays (whose rows have the same length, with no whole) and I need to know the locations of those rectangular arrays in the jagged array.
You can see the expected result here, each rectangular array has a distinct color.
This is an example of input :
[ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][X][ ][ ][ ][ ]
[ ][X][X][X][X][X][X][X]
[ ][ ][X][X][X][X][ ][ ]
[ ][X][X][X][X][ ][ ][ ]
[ ][X][X][X][X][ ][ ][ ]
[ ][ ][X][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ]
I get that in output:
[ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][A][ ][ ][ ][ ]
[ ][B][G][G][G][F][E][E]
[ ][ ][G][G][G][F][ ][ ]
[ ][D][G][G][G][ ][ ][ ]
[ ][D][G][G][G][ ][ ][ ]
[ ][ ][C][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ]
The test cases are here. The instructions to build the project are here.
There are several similar questions on StackOverflow here (mainly focused on whether it's NP-hard or not), here (only looking for the largest rectangle), here (looking for some rectangles) and here (different performance needs, efficiency is more important for me).
I spent several months in writing and implementing my own algorithm in Java as you can see here but it's terribly inefficient, it would spend several days with about 600 256*256 arrays supplied in input. I haven't evaluated this source code yet.
Is there a faster algorithm to convert a jagged array into a list of rectangular arrays and their locations in this jagged array?