Yesterday we got the question Sum of Maximum GCD from two arrays.
There was some language in it that I thought was in the gray area. And so myself and the OP exchanged a comment:
I have concern with two of your sentences: "it has successfully passed some of the test cases." If it doesn't pass all the test cases, then this is unfortunately off-topic. Also "But it does throw runtime exceptions", are these intended? It doesn't, to me, look like it should. And so you may want to re-phrase the sentence, if it does work as intended. – Peilonrayz 18 hours ago
@Peilonrayz I feel it's logically correct and that's what I've tried to better. But the website that accepts my code and runs it against their test cases masks the test cases. So all I see is the reason the code failed against them - which is listed as a runtime exception - that's what I meant when I said that. It passes for my test case on my local machine. I guess what I'm looking for is for someone to tell me if there's some obvious error that I'm making in terms of array handling or something of the sort and also if this is the most optimized way of writing this code. – sinewaver 18 hours ago
The OP is correct, logically it seems correct. And the only possible error, I know of, that can be raised is a MemoryError
. There are no index errors in the code, and should work correctly on any input given enough time and memory.
Looking at the constraints, we know \$N\$ is \$1 \le N \le 5 \times 10^5\$. Which means the worst case sized array will be around t = [(1000, 1000) for _ in range((5 * 10**5)**2)]
. Doing some basic math, I found this to be roughly ~2275GB of RAM large. Where the OP wanted to make two to three of these.
As we all know, if this were due to getting a time limit exceeded, "“Time Limit Exceeded” and programming challenges", then it'd be on-topic. However consensus shows that if it's an out of memory error, "Does getting OutOfMemoryError really mean broken code?", then it's on-topic too.
None of the five users that voted to close the question however commented to say why they're closing. And so I can only assume it's due to my comment having two upvotes. Which doesn't actually say it's broken. And so I don't think just starting a vote to re-open this question would work. Which is why I'm requesting it be re-open on Meta. If it is on-topic.