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.
You were right. Initially, when I converted your C code into C# code, I had to do few castings in the expression to overcome compilation issues. The compilation issue was coming in nested else block where you are performing square root operation. Those casting issues were related to int to float conversion. With the new castings applied when I ran you code then this particular test case failed which I've mentioned in my first comment. So, I applied this additional check to pass all test cases. I was able to fix it now. I changed the expression to apply casting on the whole R.H.S. expression instead:
n = (int)((b - Math.Sqrt(b * b - 8 * d * s)) / (2 * d));
Your entire solution is correct as is. Thank you so much for providing this feedback.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Halloween Sale
You are viewing a single comment's thread. Return to all comments →
You were right. Initially, when I converted your C code into C# code, I had to do few castings in the expression to overcome compilation issues. The compilation issue was coming in nested else block where you are performing square root operation. Those casting issues were related to int to float conversion. With the new castings applied when I ran you code then this particular test case failed which I've mentioned in my first comment. So, I applied this additional check to pass all test cases. I was able to fix it now. I changed the expression to apply casting on the whole R.H.S. expression instead:
Your entire solution is correct as is. Thank you so much for providing this feedback.