X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Minimum characters to be added at front to make string palindrome
Hard Accuracy: 43.52% Submissions: 1853 Points: 8

Given string str of length N. The task is to find the minimum characters to be added at front to make string palindrome.

Note: A palindrome is a word which reads the same backward as forward. Example : madam.

Example 1:

Input:
S = "abc"
Output: 2
Explanation: 
Add 'b' and 'c' at front of above string to make it
palindrome : "cbabc"

Example 2:

Input:
S = "aacecaaaa"
Output: 2

 

Your Task:  
You don't need to read input or print anything. Your task is to complete the function minChar() which takes a string S and returns an integer as output.

Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)

 

Constraints:
1 <= S.length <= 105

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Minimum characters to be added at front to make string palindrome

Output Window