Given two integers **n** and **k**, the task is to find the **k ^{th}** smallest element from the range

**[1, n]**after deleting all the odd numbers from the range.

**Examples:**

Input:n = 8, k = 3

Output:6

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 3^{rd}smallest.

Input:n = 8, k = 4

Output:

**Approach:** Since all odd numbers are removed so now only even numbers are left i.e. **2, 4, 6, 8, …..**

Now, the **k ^{th}** smallest element will always be

**2 * k**.

Below is the implementation of the above approach:

## C++

`// C++ implementation of the approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to return the kth smallest ` `// element from the range [1, n] after ` `// removing all the odd elements ` `int` `kthSmallest(` `int` `n, ` `int` `k) ` `{ ` ` ` `return` `(2 * k); ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `n = 8, k = 4; ` ` ` `cout << kthSmallest(n, k); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `class` `GFG { ` ` ` ` ` `// Function to return the kth smallest ` ` ` `// element from the range [1, n] after ` ` ` `// removing all the odd elements ` ` ` `static` `int` `kthSmallest(` `int` `n, ` `int` `k) ` ` ` `{ ` ` ` `return` `(` `2` `* k); ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main(String args[]) ` ` ` `{ ` ` ` `int` `n = ` `8` `, k = ` `4` `; ` ` ` `System.out.print(kthSmallest(n, k)); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of the approach ` ` ` `# Function to return the kth smallest ` `# element from the range [1, n] after ` `# removing all the odd elements ` `def` `kthSmallest(n, k): ` ` ` `return` `2` `*` `k ` ` ` `# Driver code ` `n ` `=` `8` `; k ` `=` `4` `print` `(kthSmallest(n, k)) ` ` ` `# This code is contributed ` `# by Shrikant13 ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the approach ` `using` `System; ` `class` `GFG { ` ` ` ` ` `// Function to return the kth smallest ` ` ` `// element from the range [1, n] after ` ` ` `// removing all the odd elements ` ` ` `static` `int` `kthSmallest(` `int` `n, ` `int` `k) ` ` ` `{ ` ` ` `return` `(2 * k); ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main() ` ` ` `{ ` ` ` `int` `n = 8, k = 4; ` ` ` `Console.WriteLine(kthSmallest(n, k)); ` ` ` `} ` `} ` ` ` `// This code is contributed by Code_Mech ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of the approach ` ` ` `// Function to return the kth smallest ` `// element from the range [1, n] after ` `// removing all the odd elements ` `function` `kthSmallest(` `$n` `, ` `$k` `) ` `{ ` ` ` `return` `(2 * ` `$k` `); ` `} ` ` ` `// Driver code ` `$n` `= 8; ` `$k` `= 4; ` `echo` `(kthSmallest(` `$n` `, ` `$k` `)); ` ` ` `// This code is contributed ` `// by Code_Mech ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

8

**Time Complexity:** O(1)

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.