HashMap is a part of collection in Java since 1.2. It provides the basic implementation of Map interface of Java. It stores the data in (Key, Value) pairs. To access a value you must know its key, otherwise, you can’t access it. HashMap is known as HashMap because it uses a technique Hashing. Try this problem using HashMap.
Given n key - value pairs and a seperate key in next line. If this key is found in the previous n keys then print its value otherwise print "-1".
Input: First line of input contains a single integer T which denotes the number of test cases. T test cases follows, first line of each test case contains a integer n. Second line of each test case consists of n key(String)-value(Integer) pairs space separated. Third and last line of each test case consists of a single key(String).
Output: If the key is found in the HashMap print its value otherwise print "-1".