Store Credit
InterviewTime limit5sMemory limit512 MB
Given a credit C and a list of item prices, find the two positions whose prices sum exactly to C and print them in increasing order.
- Level
Easy3 of 10
- Topics
- Array, Hash map, Two pointers, Brute force
- Solved
- No attempts yet
Problem
You receive a store credit of at a local store and want to spend it on exactly two items. You first walk through the store and write down every item on sale, which gives you a list . From that list you buy two items whose prices add up to the credit exactly.
The answer is the pair of integers giving the positions of those two items in the list, smaller number first. Positions are counted from 1.
Input
The first line contains the number of test cases . The test cases follow, each on three lines.
- The first line contains the credit you have at the store.
- The second line contains the number of items in the store.
- The third line contains integers separated by single spaces. Each integer is the price of one item.
Limits
- Every test case has exactly one pair of items that satisfies the condition.
Output
For each test case, print one line containing Case #x: followed by the positions of the two items whose prices add up to the store credit, smaller position first, separated by a single space. Here is the test case number starting from 1.