Zepruv › Coding problems

Longest Happy String

Medium · String, Greedy, Heap (Priority Queue)

A string s is called happy if it satisfies the following conditions:
Given three integers a, b, and c, return the longest possible happy string. If there are multiple longest happy strings, return any of them. If there is no such string, return the empty string "".
A substring is a contiguous sequence of characters within a string.

Example 1

Input: a = 1, b = 1, c = 7
Output: "ccaccbcc"

"ccbccacc" would also be a correct answer.

Example 2

Input: a = 7, b = 1, c = 0
Output: "aabaa"

It is the only correct answer in this case.

Constraints

Starter code (python)

class Solution(object):
    def longestDiverseString(self, a, b, c):
        """
        :type a: int
        :type b: int
        :type c: int
        :rtype: str
        """
        

Related problems

Previous: K-Concatenation Maximum Sum · Next: Minimum Absolute Difference · All problems

Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.