409. Longest Palindrome Problem Statement Given a string s which consists of lowercase…
- User
- Longest Palindrome Problem Statement Given a string s which consists of lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters. Constraints Letters are case sensitive, for example, "Aa" is not considered a palindrome. 1 <= s.length <= 2000 s consists of lowercase and/or uppercase English letters only. Examples Example 1 Input: s = "abccccdd" Output: 7 Explanation: One longest palindrome that can be built is "dccaccd", whose length is 7. Example 2 Input: s = "a" Output: 1 Explanation: The longest palindrome that can be built is "a", whose length is 1.
Q- what you explain the problem statement ? You are given a string “s” you task to find the number of characters that can construct the the longest palindrome string from it Q- what is the input/output format ?
Input : s:string Output : string
Q- we have a definition we need to specify ? A plandfrom string is a spring that you can read foreword and backward
Q- do you practical solution ?
To build the longest palindrom possible string We need to use all the characters of even “occurrences “ + the maximum number of char “with” odd occurrences this number most be odd For example Abccccdd
Here for example we have c → repeated 4 times (even pair) dd → repeated 2 times (even pair)
A and b reperarte only one time (1) —> so w peak one of them
Q- how to solve it using functional programming ?
Step 1 : compute the hashmap from the “s” Step 2 : filter the hashmap by summing the values of char that has even number of occurrences Step 3 : peek the value of the element that has the biggest odd number of occurrence
Q- exmple
"abccccdd"
Step 1 : “abccccdd” Compute the hashmap {“a”:1,”b”:1,”c”:4,”d”:2} Step 2 : filter v1=6 Step3 : peak v2=1 Return 7
Q- use more mathemiactical notation to formalize my thinking process here ?
- Assistant