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 are the author of Highest Value Palindrome problem. I was going through your solution and in your condition below condition
else if((mark[l]==1 || mark[r]==1) && k>=1)
{
k-=1;
ans[l] = ans[r] = '9';
}
You are decrementing k by 1 but it should be decremented by 2 because we are changing both ans[l] and ans[r] in theelse part which requires 2 moves. If only 1 move is left how is this condition justified!!!
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Highest Value Palindrome
You are viewing a single comment's thread. Return to all comments →
Hi @nabila_ahmed
You are the author of Highest Value Palindrome problem. I was going through your solution and in your condition below condition else if((mark[l]==1 || mark[r]==1) && k>=1) { k-=1; ans[l] = ans[r] = '9'; } You are decrementing k by 1 but it should be decremented by 2 because we are changing both ans[l] and ans[r] in theelse part which requires 2 moves. If only 1 move is left how is this condition justified!!!