Count And Say
Write as you speak is a special sequence of strings that starts with string “1” and after one iteration you rewrite the sequence as whatever you speak.
Example :
The first few iterations of the sequence are :
First iteration: “1”
As we are starting with one.
Second iteration: “11”
We speak “1” as “one 1” then we write it as “11”
Third iteration: “21”
We speak “11” as “Two 1” then we write it as “21”
Fourth iteration: “1211”
We speak “21” as “one 2, one 1” then we write it as “1211”
Fifth iteration: “111221”
We speak “1211” as “one 1, one 2, two 1” then we write it as “111221”
Sixth iteration: “312211”
We speak “111221” as “three 1, two 2, one 1” then we write it as “312211”
You will be given a single positive integer N, Your task is to write the sequence after N iterations.
Input Format:
The first line of the input contains a single positive integer T, denoting the number of test cases.
The first line of each test case contains a single integer N, denoting the number of iterations.
Output Format:
For each query print the string that represents the sequence after the nth iteration.
Note:
You don't have to print anything, it has already been taken care of. Just Implement the given function.
Constraints:
1 <= T <= 10
1 <= N <= 30
Time Limit: 1 sec
CodingNinjas
author
2y
Simulation
- The best way to solve this problem is to simulate it.
- We will start our simulation with the single S. S will store the current sequence. At first, the S will be equal to “1”.
- Then we will repe...read more
Help your peers!
Add answer anonymously...
Top Expedia Group Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Top HR questions asked in Expedia Group Software Developer Intern
>
Expedia Group Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app