Find P-th Number
All submissions for this problem are available.
Alice had a bag where each number from 1 to N was present in it. After a magic trick she either removes all even numbers or all odd numbers from the bag.
Given the kind of trick she has performed find the Pth smallest number in the bag after the trick. For example P = 1 denotes the smallest number present.
First line contains T, the number of test cases. Each test case consists of N, a string S and an integer P in single line.
S will be either “odd” or “even”(quotes for clarity), denoting the kind of trick Alice has performed.
Note: It is guaranteed that P will be less than or equal to remaining items in the bag.
For each test case, print the required answer in one line.
Should contain all the constraints on the input data that you may have. Format it like:
- 1 ≤ T ≤ 100
- 1 ≤ N ≤ 103
- P ≥ 1
Input: 2 4 odd 2 5 even 2 Output: 4 3
After performing the “odd” trick the numbers 1 and 3 get removed from the bag.
Numbers 2 and 4 are left in the bag.
2nd smallest number is 4 now.
After performing the “even” trick the numbers 2 and 4 get removed from the bag.
Numbers 1, 3 and 5 are left in the bag.
2nd smallest number is 3 now.
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
Fetching successful submissions