- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this problem, we are given two integer values n and k. Our task is to *find kth smallest number in range [1, n] when all the odd numbers are deleted. *

We need to find the kth smallest number in the range [1, n] which contains only even values.

So, from range [1, 5] -> number will be 2, 4.

**Let’s take an example to understand the problem, **

**Input: **n = 12, k = 4

**Output: **8

**Explanation: **

Even elements in the range [1, n] : 2, 4, 6, 8, 10, 12

The 4th smallest element is 8.

**Solution approach: **

The solution is simple as we need to find the kth element from even numbers upto n. This can be easily calculated using the formula,

Element = 2*k.

#include <bits/stdc++.h> using namespace std; int main() { int n = 124, k = 12; if(n > 2*k){ cout<<"kth smallest number is "<<(2 * k); } else cout<<"kth smallest number cannot be found"; return 0; }

kth smallest number is 24

- Related Questions & Answers
- Smallest possible number divisible by all numbers from 1 to n in JavaScript
- Program to find kth smallest n length lexicographically smallest string in python
- Find smallest number n such that n XOR n+1 equals to given k in C++
- Kth Smallest Number in Multiplication Table in C++
- Kth odd number in an array in C++
- Python Program to Find All Numbers which are Odd and Palindromes Between a Range of Numbers
- kth smallest/largest in a small range unsorted array in C++
- Program to find nearest number of n where all digits are odd in python
- Count all the numbers in a range with smallest factor as K in C++
- Print all odd numbers and their sum from 1 to n in PL/SQL
- Python program to print all odd numbers in a range
- Find numbers with K odd divisors in a given range in C++
- Generating range of numbers 1…n in SAP HANA
- Program to find count of numbers having odd number of divisors in given range in C++
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors in C++

Advertisements