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.
That's a good solution but in the for loop instead of
for (int a=i;j>a; a++)
you need to use
for (int a=i;j>=a; a++)
so that it also checks for the value of a itself and will return the correct and required output.In the case what you have done there might be wrong answer for some of the test cases.
HOPE THIS HELPS!!!
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Beautiful Days at the Movies
You are viewing a single comment's thread. Return to all comments →
That's a good solution but in the for loop instead of for (int a=i;j>a; a++) you need to use for (int a=i;j>=a; a++) so that it also checks for the value of a itself and will return the correct and required output.In the case what you have done there might be wrong answer for some of the test cases. HOPE THIS HELPS!!!