FastPrepCount and Say

Count and Say

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREENONSITE INTERVIEW
Learn

Problem statement

The count-and-say sequence begins with countAndSay(1) = "1". Each later term describes the maximal equal-digit runs of the previous term as count followed by digit.

Return the n-th term.

Function

countAndSay(n: int) → String

Examples

Example 1

n = 1return = "1"

The first term is defined as 1.

Example 2

n = 4return = "1211"

Term 3 is 21, which is read as one 2 and one 1.

Constraints

  • 1 <= n <= 30.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public String countAndSay(int n) {
  // Write your code here.
}
n1
expected"1"
Checking account…