Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding
Ninjas X Naukri.com

Problem of the day

The Look-And-Say sequence is a sequence of positive integers. The sequence is as follows:

1, 11, 21, 1211, 111221, 312211, 13112221,...

This sequence is constructed in the following way:

```
The first number is 1.
This is read as “One 1”.
Hence, the second number will be 11.
The second number is read as “Two 1s”.
Hence, the third number will be 21.
The third number is read as “One 2, One 1”.
Hence, the fourth number will be 1211. And so on.
The fourth term is read as “One 1, One 2, Two 1s”.
Hence, the fifth term will be 111221. And so on.
```

Given an integer N, find the Nth term of the sequence.

Detailed explanation

```
1 <= T <= 30
1 <= N <= 40
Where 'T' is the number of test cases and 'N' is the given sequence index.
Time Limit: 1 sec
```

```
3
1
2
3
```

```
1
11
21
```

```
The first term is 1.
The second term is 11.
The third term is 21.
```

```
1
6
```

```
312211
```