2745. Construct the Longest New String
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 54% Topics: Math, Dynamic Programming, Greedy, Brainteaser
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(1)
# Space: O(1)
# constructive algorithms, math
class Solution(object):
def longestString(self, x, y, z):
"""
:type x: int
:type y: int
:type z: int
:rtype: int
"""
return ((min(x, y)*2+int(x != y))+z)*2
Solution from kamyu104/LeetCode-Solutions · MIT