Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@shashi1iitk | 398 |

@Suniti Jain | 114 |

@ankish2000nayak | 104 |

@gopalsethlnct | 94 |

@esmadhan | 90 |

@senthil1185 | 90 |

@gyanadipta07 | 89 |

@satwikdash2000 | 85 |

@varunmishra3040 | 83 |

@gamec1634 | 82 |

@pj_1721 | 80 |

Complete Leaderboard |

Given a decimal number **m**. Convert it into a binary string and apply **n** iterations, in each iteration **0** becomes **01**, and **1** becomes **10**. Find the** k**th (1-indexing) character in the string after **n**th iteration.

**Example 1:**

**Input:** m = 5, n = 2, k = 5
**output:** 0
**Explanation:** Binary represntation of m
is "101", after one iteration binary
reprentation will be "100110", and after
second iteration binary repreentation
will be "100101101001".

**Example 1:**

**Input:** m = 5, n = 2, k = 1
**output:** 1
**Explanation:** Binary represntation of m
is "101", after one iteration binary
reprentation will be "100110", and after
second iteration binary repreentation
will be "100101101001".

**Your task:**

You do not need to read any input or print anything. The task is to complete the function **kthCharacter()**, which takes 3 integers m, n, and k as input and returns a character.

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

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

**Constraints:**

0 ≤ m ≤ 50

0 ≤ n ≤ 10

K is a valid index

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?

Yes
Find k-th character in string

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.