Skip to content

Practice The k-th Lexicographical String of All Happy Strings of Length n

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1415
LeetCode Problem

The k-th Lexicographical String of All Happy Strings of Length n

Problem Statement

A happy string uses only a, b, and c, with no equal adjacent characters. Sort all such strings of length n in lexicographical order. Return the kth string, counting from 1, or the empty string if fewer than k strings exist.

Source: The k-th Lexicographical String of All Happy Strings of Length n on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 1, k = 3
Output
"c"

# Example 2

Input
n = 1, k = 4
Output
""

# Example 3

Input
n = 3, k = 9
Output
"cab"

Constraints

1 <= n <= 10
1 <= k <= 100

Related LeetCode Problems

Practice more problems similar to The k-th Lexicographical String of All Happy Strings of Length n.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.