less than 1 minute read

2325. Decode the Message (easy)

class Solution:
    def decodeMessage(self, key: str, message: str) -> str:
        d = {}
        d[' '] = ' '
        index = 0
        for i, elem in enumerate(key):
            if elem == ' ': continue
            if elem in d: continue
            d[elem] = chr(index + ord('a'))
            index += 1

        # print(d)
        return ''.join([d[x] for x in message])

2130. Maximum Twin Sum of a Linked List (medium)

class Solution:
    def pairSum(self, head: Optional[ListNode]) -> int:
        arr = []
        while head:
            arr.append(head.val)
            head = head.next

        res = -1
        n = len(arr)
        for i in range(n // 2):
            res = max(res, arr[i] + arr[n - 1 - i])
        
        return res

2131. Longest Palindrome by Concatenating Two Letter Words (medium)

class Solution:
    def longestPalindrome(self, words: List[str]) -> int:
        counter = Counter(words)
        res = 0

        for word in words:
            if word[0] == word[1] and counter[word] % 2 == 1:
                counter[word] -= 1
                res = 2
                # centered

        for word in words:
            # print(counter)
            if word[::-1] not in counter:
                continue
            if counter[word[::-1]] > 0 and counter[word] > 0:
                res += 4
                counter[word] -= 1
                counter[word[::-1]] -= 1
            
        return res