Expand the pond

I’ve tried to solve this problem, It was giving TLE. I reffered to doubts forum for optimized approach(in c++) and applied that in java. It is still giving TLE for 3 test cases. Is it due to the language java or c++, that same approach is accepted for one and not for the other?

Please help me out.

My solution : https://ide.codingblocks.com/s/230134

Reference: https://ide.codingblocks.com/s/138518?_ga=2.251000006.1334989375.1588653743-397636666.1585678639

@vkth
Issue is with line 65
You’re making a boolean array of size K each time you find a 0
Instead use a hashmap
Add neighbour regions to hashmap
Since hashmap wont store duplicates
In the end just iterate over hashmap values and add to get local max result

Thank you so much. :slight_smile:

1 Like