Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

Given an integer n. Return the nth row of the following look-and-say pattern.

1

11

21

1211

111221

**Example 1:**

**Input:**
n = 5
**Output:** 111221
**Explanation: **The 5^{th} row of the given pattern
will be 111221.

**Example 2:**

**Input:**
n = 3
**Output:** 21
**Explanation: **The 3^{rd} row of the given pattern
will be 21.

**Your Task: **

You dont need to read input or print anything. Complete the function **lookandsay()** which takes integer n as input parameter and returns a string denoting the contents of the nth row of given pattern.

**Expected Time Complexity:** O(2^{n})

**Expected Auxiliary Space: **O(2^{n-1})

**Constraints:**

1 ≤ n ≤ 30

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Look and Say Pattern

...