Dictionaries and Maps

Task
Given N names and phone numbers, assemble a phone book that maps friends’ names to their respective phone numbers. You will then be given an unknown number of names to query your phone book for; for each name queried, print the associated entry from your phone book (in the form name=phoneNumber) or Not found if there is no entry for name.

Note: Your phone book should be a Dictionary/Map/HashMap data structure.

 

Sample Input

Sample Output

Input (stdin)
3
sam 99912222
tom 11122222
harry 12299933
sam
edward
harry
Your Output (stdout)
sam=99912222
Not found
harry=12299933
Expected Output
sam=99912222
Not found
harry=12299933

SOLID – Single Responsibility Principle

The Single Responsibility principle (SRP) states that:

There should never be more than one reason for a class to change.

We can relate the “reason to change” to “the responsibility of the class”. So each responsibility would be an axis for change. This principle is similar to designing classes which are highly cohesive. So the idea is to design a class which has one responsibility or in otherwords caters to implementing a functionality . I would like to clarify here that one responsibility doesnt mean that the class has only ONE method. A responsibility can be implemented by means of different methods in the class.

Why is that this principle is required?

(more…)

Let’s Review – String Usage

Given a string, S , of length N that is indexed from 0  to N-1 , print its even-indexed and odd-indexed characters 2 as space-separated strings on a single line (see the Sample below for more detail).

Note: 0 is considered to be an even index.

Input Format

The first line contains an integer T, (the number of test cases).
Each line i  of the T subsequent lines contain a String, S

Sample Input

Sample Output

Congratulations, you passed this test case in 0.0500/4 seconds!
Input (stdin)
2
Hacker
Rank
Your Output (stdout)
Hce akr
Rn ak
Expected Output
Hce akr
Rn ak