Longest Happy String Problem Statement

Given three non-negative integers X, Y, and Z, determine the longest happy string. A happy string is defined as a string that contains only the letters 'a', 'b', and 'c' without having any three consecutive letters being the same.

Explanation:

You need to construct the longest string possible such that it has 'a' at most X times, 'b' at most Y times, and 'c' at most Z times.

If there are multiple strings with maximum length, any of these strings can be returned.

Input:

The first line contains an integer 'T' representing the number of test cases. Each test case consists of one line containing three space-separated integers: X, Y, and Z.

Output:

For each test case, return "1" if a correct happy string can be formed, otherwise return "0".

Example:

Input:
2
1 1 7
2 2 1
Output:
1
1

Constraints:

  • 1 ≤ T ≤ 5
  • 0 ≤ X, Y, Z ≤ 10^3
  • X + Y + Z ≥ 1
Note:
You are not required to input or print anything. Focus on implementing the function to achieve the desired result.
Be the first one to answer
Add answer anonymously...
Salesforce Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter