Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Sprinklr Online Coding Test Question

Правка en1, от WitchDoc, 2020-08-26 16:57:30

Summary of the question:

You are given two numbers L and R 1 <= L <= R <= 10^18. We define a lucky number as a number which contains the pattern “101” in its bit representation. Given an integer K, we need to find the Kth lucky number between L and R (both inclusive) if it exists, otherwise return -1.

My Approach:

So I tried to check every no. between L and R if it had 101 in its bit representation. For some testcases it passed, but for others I got TLE.

Please can someone provide me the most optimal solution/approach to this and these types of questions.

Теги #help, #bits, #tle

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский WitchDoc 2020-08-26 16:58:08 2 Tiny change: ' questions.' -> ' questions?'
en1 Английский WitchDoc 2020-08-26 16:57:30 630 Initial revision (published)