ADOBE Coding Question – Solved

10 Live
Number in a range You are given three integers L, R, and K. A number X represents a lucky number if the binary representation of X contains the pattern 101 as a substring. Determine the Kth lucky number between L and R. If the Kth lucky number does not exist, then print -1. Function description Complete the solve function. This function takes the following 3 parameters and returns the Kth lucky number in between L and R. Parameters: - L: Represents an integer denoting the value of L - R: Represents an integer denoting the value of R - K: Represents an integer denoting the Kth lucky number to be found Input format for custom testing Note: Use this input format if you are testing against custom input or writing code in a language where we don't provide boilerplate code. - The first line contains T, which represents the number of test cases. - For each test case: - The first line contains three space-separated integers L, R, and K. Output format For each test case, print the Kth lucky number in the range [L, R] on a new line. If the Kth lucky number does not exist, then print -1. Constraints 1 ≀ T ≀ 200 1 < L ≀ R ≀ 10^18 1 ≀ K ≀ 10^18 Sample input 6 5 40 6 5 12 4 9 20 5 7 7 1 14 37 4 13 25 4 Sample output 21 -1 -1 -1 23 22 Explanation: For test case 1: All lucky numbers between 5 and 40 are 5, 10, 11, 13, 20, 21, 22, 23, 26, 27, 29, 37, and 40. The sixth lucky number is 21. For test case 2: All lucky numbers between 5 and 12 are 5, 10, and 11. There are less than 4 lucky numbers, so print -1. For test case 3: All lucky numbers between 9 and 20 are 10, 11, and 13. There are less than 5 lucky numbers, so print -1. For test case 4: There are 0 lucky numbers between [7, 7], so print -1. For test case 5: All lucky numbers between 14 and 37 are 20, 21, 22, 23, 26, 27, 29, and 37. The fourth lucky number is 23. For test case 6: All lucky numbers between 13 and 25 are 13, 20, 21, 22, and 23. The fourth lucky number is 22. Note: Your code must be able to print the sample output from the provided sample input. However, your code is run against multiple hidden test cases. Therefore, your code must pass these hidden test cases to solve the problem statement. Limits Time Limit: 1.0 sec(s) for each input file Memory Limit: 256 MB Source Limit: 1024 KB Allowed Languages: Bash, C, C++14, C++17, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java 8, Java 14, JavaScript(Node.js), Julia, Kotlin, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, Python 3.8, Racket, Ruby, Rust, Scala, Swift, TypeScript, Visual Basic

Asked in: ADOBE

Image of the Question

Question Image Question Image Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| A company is organizing a batch process, where each batch consists of several t… |
| A digital art gallery has an art collection which is represented as a binary st… |
| Given a series of integer intervals, determine the size of the smallest set tha… |
| A forklift operator navigates products within an automotive parts warehouse. Th… |
| School renovation Given N classrooms in a school and each classroom has a ca… |
| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |