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
Find k-th character in string
Basic Accuracy: 12.9% Submissions: 559 Points: 1

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 kth (1-indexing) character in the string after nth 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(2n)
Expected Auxiliary Space: O(2n)

Constraints:
0 ≤ m ≤ 50
0 ≤ n ≤ 10
K is a valid index

to report an issue on this page.

Editorial

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

Yes

All Submissions

My Submissions:

Login to access your submissions.

Find k-th character in string

Output Window