Given two integers N and K, the task is to find the element at the Kth position if all odd numbers from 1 to N are written down in increasing order followed by all the even numbers from 1 to N in increasing order.
Input: N = 10, K = 3
The required sequence is 1, 3, 5, 7, 9, 2, 4, 6, 8 and 10.
Input: N = 7, K = 7
Approach: It is known that the Nth even number is given by 2 * K and the Nth odd number is given by 2 * K – 1. But since the even numbers are written after (N + 1) / 2 odd numbers here. Therfore, Kth even number is given by 2 * (K – (N + 1) / 2) and the odd numbers will remain the same as 2 * K – 1
Below is the implementation of the above approach:
Time Complexity: O(1)
- Find element position in given monotonic sequence
- Find the position of the last removed element from the array
- Check if the bracket sequence can be balanced with at most one change in the position of a bracket | Set 2
- Check if the bracket sequence can be balanced with at most one change in the position of a bracket
- Count Derangements (Permutation such that no element appears in its original position)
- Find the position of box which occupies the given ball
- Find the value at kth position in the generated array
- Find out the correct position of the ball after shuffling
- Find position of the given number among the numbers made of 4 and 7
- Find F(n) when F(i) and F(j) of a sequence are given
- Find n-th term in sequence 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, ....
- Program to find sum of the given sequence
- Find Recurring Sequence in a Fraction
- Program to find Nth term of the Van Eck's Sequence
- Find the lexicographical next balanced bracket sequence
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.