Let us define the Laughter sequence as a sequence of strings only containing either the character "H" or "A". This sequence is defined recursively as Lo = H L₁ = A Li Li-2 Li-1, for i > 1 (Note: S₁ S₂ means we concatenate S₁ and S₂.) The first few strings in the Laughter sequence are H. A. HA, AHA. HAAHA. AHAHAAHA. Given i and k, determine whether the kth character in L, is an H or an A. Input Format Input consists of one test case. Each test case consists of one line with two space separated integers i and k denoting the index of the string in the Laughter sequence, and the index of the character to be checked. k is a 0-based index. Constraints 0 ≤ i ≤ 105
Let us define the Laughter sequence as a sequence of strings only containing either the character "H" or "A". This sequence is defined recursively as Lo = H L₁ = A Li Li-2 Li-1, for i > 1 (Note: S₁ S₂ means we concatenate S₁ and S₂.) The first few strings in the Laughter sequence are H. A. HA, AHA. HAAHA. AHAHAAHA. Given i and k, determine whether the kth character in L, is an H or an A. Input Format Input consists of one test case. Each test case consists of one line with two space separated integers i and k denoting the index of the string in the Laughter sequence, and the index of the character to be checked. k is a 0-based index. Constraints 0 ≤ i ≤ 105
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 6PE
Related questions
Question
Need help in solving the problem explained in the screenshot in python. Need the time complexity to be a minimum as possible, so using Binary Search would be the best approach.
The code
def solve(n,k): n, k = list(map(int,input().rstrip().split(" "))) |
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 3 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning