Given two integers n and k, the task is to find the kth smallest element from the range [1, n] after deleting all the odd numbers from the range.
Input: n = 8, k = 3
After deleting all the odd numbers from the range [1, 8]
2, 4, 6 and 8 are the only numbers left and 6 is the 3rd smallest.
Input: n = 8, k = 4
Approach: Since all odd numbers are removed so now only even numbers are left i.e. 2, 4, 6, 8, …..
Now, the kth smallest element will always be 2 * k.
Below is the implementation of the above approach:
Time Complexity: O(1)
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Find the number of divisors of all numbers in the range [1, n]
- Program to find count of numbers having odd number of divisors in given range
- Number of ways to obtain each numbers in range [1, b+c] by adding any two numbers in range [a, b] and [b, c]
- Count all the numbers in a range with smallest factor as K
- Find the smallest twins in given range
- Find XOR of numbers from the range [L, R]
- Smallest number divisible by first n numbers
- Find the deleted value from the array when average of original elements is given
- Find numbers with K odd divisors in a given range
- Find numbers with n-divisors in a given range
- Arrange given numbers to form the smallest number
- Smallest n digit number divisible by given three numbers
- Find a range of composite numbers of given length
- Find smallest possible Number from a given large Number with same count of digits
- Find all the possible numbers in a range that can be evenly divided by its digits
- Form smallest number using indices of numbers chosen from Array with sum less than S
- Numbers that are not divisible by any number in the range [2, 10]
- Find the smallest number whose digits multiply to a given number n
- Find the highest occurring digit in prime numbers in a range
- Count of Numbers in Range where the number does not contain more than K non zero digits
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.