Tap here to switch tabs
Problem
Submissions

Problem: K-th Lexicographical Happy String of Length n

K-th Lexicographical Happy String of Length n asks you to return the k-th alphabetically ordered string of length n with no equal adjacent characters, or an empty string if too few exist.

Statement

A happy string is defined as a string that:

  • Consists only of characters from the set ['a', 'b', 'c'].

  • Does not contain any two adjacent characters that are equal (that is, s[i] != s[i + 1] for all valid indices i).

Given two integers n and k, consider all happy strings of length n sorted in lexicographical order.

Return the kthk^{ {th}} happy string of length n from this sorted list. If there are fewer than k happy strings of length n, return an empty string "".

Constraints:

  • 1≤1 \leq n ≤10\leq 10

  • 1≤1 \leq k ≤100\leq 100

⋮
Tap here to switch tabs
Problem
Submissions

Problem: K-th Lexicographical Happy String of Length n

K-th Lexicographical Happy String of Length n asks you to return the k-th alphabetically ordered string of length n with no equal adjacent characters, or an empty string if too few exist.

Statement

A happy string is defined as a string that:

  • Consists only of characters from the set ['a', 'b', 'c'].

  • Does not contain any two adjacent characters that are equal (that is, s[i] != s[i + 1] for all valid indices i).

Given two integers n and k, consider all happy strings of length n sorted in lexicographical order.

Return the kthk^{ {th}} happy string of length n from this sorted list. If there are fewer than k happy strings of length n, return an empty string "".

Constraints:

  • 1≤1 \leq n ≤10\leq 10

  • 1≤1 \leq k ≤100\leq 100