Posts

Longest Palindrome length in sub-array with rearrange

Problem statement : Find the longest even palindrome length of the sub array from the given string of digits. The palindrome can be formed by rearranging the characters as well. Example : Given a string "1234535498" The palindrome formed can be 345543 and the length is 6. My Solution: Create a boolean array which will be true if it can form a palindrome. Find the contiguous boolean subarray with maximum number of true values. If the length is odd rerun the same with the subarray. Comments are welcome to provide a better solution or evaluate this solution. Algorithm: Iterate through the input string character by character. For each character, have a counter and increment it for each loop. Check if the character is present in the character array and get the last index of it. if the last index is not of -1, insert true in the boolean array for the last index and the counter. finally insert the character to the character array for the counter. After the...