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.
Highest Value Palindrome
Highest Value Palindrome
Sort by
recency
|
528 Discussions
|
Please Login in order to post a comment
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!!!
@Xromeo
I saw your solution in JAVA but I have a thing to ask..in the below condition else if (k - changes >= 1 && s.charAt(left) != s.charAt(right)) {
In this condition, you are changing two characters but incrementing changes by 1. Why? For the string "092282" with k = 3, I debugged the code and in first loop the array was [2, 9, 2, 2, 9, 2] but in the above condition you are actually changing the values of both left and right index but incrementing the change by 1. I think it should be 2 . Am I mising something in the logic?
My answer with Typescript, simple