A shipping yard weighs every pallet in today's batch. To build the daily weight manifest, the yard sorts these weights into non-decreasing order. Given the unsorted weights and a target weight, find every position (0-indexed) in the sorted manifest whose weight equals the target, listed in increasing order of position.
Line 1: two integers n and target, separated by a space.
Line 2: n space-separated integers, the unsorted pallet weights.
1 <= n <= 20000 <= weight <= 10^6 for every pallet weight0 <= target <= 10^6Print an integer k, the number of matching positions.
If k > 0, print a second line with the k matching positions, in increasing order and separated by spaces. If k = 0, do not print a second line.
Example 1
Input
5 2 1 2 5 2 3
Expected
2 1 2
Explanation
Sorting [1,2,5,2,3] gives [1,2,2,3,5]. The value 2 occupies positions 1 and 2 in this sorted manifest, so the output is k=2 followed by "1 2".
Example 2
Input
5 4 1 2 5 2 3
Expected
0
Explanation
The sorted manifest is [1,2,2,3,5], which contains no value equal to 4, so k=0 and no second line is printed.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →