Count and Say Problem
Count and Say Problem — ExecCode Easy DSA Practice
Solve the Count and Say problem on ExecCode. Free online easy DSA practice in String. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given a positive integer n, return then^thelement of the count-and-say sequence. Your task is to the count-and-say sequence is a sequence of digit strings defined by the recursive formula: - countAndSay(1) = "1" - countAndSay(n) is the run-length encoding of countAndSay(n - 1). Run-length encoding (RLE) is a string compression method that works by replacing each maximal group of consecutive identical characters with the concatenation of the length of the group followed by the character itself. Return the required answer exactly as shown in the examples.
Examples
Input {"n": 1}; Output 1. Input {"n": 4}; Output 1211. Input {"n": 2}; Output 11
Constraints
1 <= n <= 30
Practice Count and Say free on ExecCode. Browse DSA problems, topic map, and placement guides.