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.
Isn't this incorrect? The if statement is going to give a false positive and allow a zero area. It should just be > not >=. I mean, it works with the test cases, I think, but it's not what the algorithm asked for.
I did it this way, too (using B > 0 && H > 0) but after reading everyone else's answers here initializing the flag to true and using B <= 0 || H <= 0 I realized that's technically more efficient because it wouldn't have to evaluated the second conditional statement if the first failed whereas using && will always require two comparisons.
Am I being crazy? XD
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Static Initializer Block
You are viewing a single comment's thread. Return to all comments →
Isn't this incorrect? The if statement is going to give a false positive and allow a zero area. It should just be > not >=. I mean, it works with the test cases, I think, but it's not what the algorithm asked for.
I did it this way, too (using B > 0 && H > 0) but after reading everyone else's answers here initializing the flag to true and using B <= 0 || H <= 0 I realized that's technically more efficient because it wouldn't have to evaluated the second conditional statement if the first failed whereas using && will always require two comparisons.
Am I being crazy? XD