We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Ema's Supercomputer
Ema's Supercomputer
Sort by
recency
|
316 Discussions
|
Please Login in order to post a comment
An alternative Python solution:
My Python solution:
After all, the best method is brute force. The idea is simple, you only need to travese the grid to find possible plus and then loop through these valid pluses to get the max product. Here is my js for the function. It might not be optimized, so feel free to upgrade it further.
I finally got some code that worked! For my approach, I found every cell that was good. Then, I checked how far each arm could reach. The largest plus with the middle in that cell would then be the minimum size of arms. However, we also need to add all of the pluses that are smaller than that. Then, we can compare every plus with every other plus to see if they overlap. If they don't overlap, we record the product. Once we have all the products, we return the largest one.
It took me over a day figuring this out. I finally devised a working algorithm while I was thinking about it at work. These problems are all about solving the math (getting exactly how the algorithm works). Once I have the algorithm down, it took me just 1-2 hours for actual implementation. Trying to just code a solution to these problems without a working plan (which I tried initially) will be a disaster.
My solution uses brute force. It essentially tries all possible permutations and pick the best one. My approach is to use the center to slowly expand out and check for 'G'. It'll be too much to explain everything but if you're interested, you can take a look at the code. Coded in python: