When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
1 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
Could you explain how your current solution roughly works? I am having a hard time figuring out whether it's O(n) or O(n^2) with the use of high-level templated code. I understand what the C++ functions do on an individual level. It looks like you're trying to basically do this C-like solution of iterating forwards once and backwards once? Neither your nor this solution does the follow up challenge of using O(1) space, though:
https://leetcode.com/problems/product-of-array-except-self/solutions/4990895/c-prefix-and-postfix/
lol, I like how the Solutions tab of that leetcode question is full of people who ignored the "without using division" part of the exercise.
In order to figure out why the performance isn't great, I recommend using godbolt to glance at the generated Assembly: https://godbolt.org/z/14h3hzM13
I've set that godbolt page up to use the flags mentioned here, for both the execution and compiler windows
I was thinking that this more C-like solution might produce less lines of Assembly, but it also produces about 750 lines: https://godbolt.org/z/v7cvT4Mce
I think the performance mostly just sucks cause of leetcode compiling the program with -fsanitize=address, cause removing that flag during compilation brings the number of generated Assembly lines down to 100.
(throwing the generated Assembly from both programs on godbolt into text files, and diffing them shows they're pretty much identical, both with and without fsanitize)
Okay yeah, your solution is completely fine, it's apparently just that the people behind leetcode don't know shit about how to properly time your code (or are just greedy), cause it seems like they repeat their tests so few times that my percentage fluctuates this much when I resubmit that exact same C-like solution from that person I linked
Thanks, I got it after a few hours :)
Make sure to read this part
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity