Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

50. Count and Say

MediumDay 15 of 60Strings

The count-and-say sequence starts with "1". Each next term is made by reading the previous term aloud in groups of equal digits: for every group, write how many digits it has followed by the digit. For example, "3322251" is read as two 3s, three 2s, one 5, one 1, giving "23321511". Given n, return the n-th term.

Example 1
Input: n = 4
Output: "1211"
Terms: "1", "11" (one 1), "21" (two 1s), "1211" (one 2, one 1).
Example 2
Input: n = 1
Output: "1"
Constraints
  • 1 <= n <= 30
Hints
Frequently asked at: Meta, Amazon, Adobe, Zoho
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min