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.
IF YOU SUCCEED AT ALL EXCEPT ONE TEST CASES, READ THIS POST: With one of the test cases, the numbers are so large that even with a line like this (which seems fine)...
long long CalculateVolume() { return l * b * h; };
...The result of this, while converted to a long long eventually, is originally in integer format during multiplication, causing overflow hence producing a negative volume!
I don't know if there's a more elegant way to do this, but I just decided to do it this way and it worked.
long long CalculateVolume() { return (long long) l * (long long) b * (long long) h; };
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Box It!
You are viewing a single comment's thread. Return to all comments →
IF YOU SUCCEED AT ALL EXCEPT ONE TEST CASES, READ THIS POST: With one of the test cases, the numbers are so large that even with a line like this (which seems fine)...
long long CalculateVolume() { return l * b * h; };
...The result of this, while converted to a long long eventually, is originally in integer format during multiplication, causing overflow hence producing a negative volume!
I don't know if there's a more elegant way to do this, but I just decided to do it this way and it worked. long long CalculateVolume() { return (long long) l * (long long) b * (long long) h; };