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 on a new line in the form
name=phoneNumber; if an entry for name is not found, print
Not found instead.
Note: Your phone book should be a Dictionary/Map/HashMap data structure.
The first line contains an integer, n, denoting the number of entries in the phone book.
Each of the n subsequent lines describes an entry in the form of 2 space-separated values on a single line. The first value is a friend’s name, and the second value is an 8-digit phone number.
After the n lines of phone book entries, there are an unknown number of lines of queries. Each line (query) contains a name to look up, and you must continue reading lines until there is no more input.
Note: Names consist of lowercase English alphabetic letters and are first names only.
1 ≤ n ≤10^5
1 ≤ queries ≤10^5
On a new line for each query, print
Not found if the name has no corresponding entry in the phone book; otherwise, print the full name and phoneNumber in the format
Retrieving user input is probably the biggest challenge when working on Hacker Rank problems.
Need to review STDIN and all that jazz.
Given a string, S, of length N that is indexed from 0 to N−1, print its even-indexed and odd-indexed characters as 2 space-separated strings on a single line (see the Sample below for more detail).
The first line contains an integer, T (the number of test cases).
Each line ii of the T subsequent lines contain a String, S.
- 1 ≤ T ≤10
- 2 ≤ length of S ≤10000
Test Case 0: S=“Hacker”
The even indices are 0, 2, and 4, and the odd indices are 1, 3, and 5. We then print a single line of 2 space-separated strings; the first string contains the ordered characters from S‘s even indices (Hce), and the second string contains the ordered characters from S‘s odd indices (akr).
Test Case 1: S=“Rank”
The even indices are 0 and 2, and the odd indices are 1 and 3. We then print a single line of 2 space-separated strings; the first string contains the ordered characters from S‘s even indices (Rn), and the second string contains the ordered characters from S‘s odd indices (ak).
So I had a hard time with this challenge because I misunderstood the problem. I thought the T and S arguments were independent of each other. However, they are not. The value of S is dependent on the value of T. So for each test case (T), there is one substring (S). Thus, the trick is to use T to prompt the number of user inputs for S, and then store the value of S in an array.
Took me an entire day and 1 Kevin Liu to figure all of this out.
Original problem here.
Complete the code in the editor below. The variables i, d, s and are already declared and initialized for you. You must:
- Declare 3 variables: one of type int, one of type double, and one of type String.
- Read 3 lines of input from stdin (according to the sequence given in the Input Format section below) and initialize your variables.
- Use the operator to perform the following operations:
- Print the sum of i plus your int variable on a new line.
- Print the sum of d plus your double variable to a scale of one decimal place on a new line.
- Concatenate s with the string you read as input and print the result on a new line.
is the best place to learn and practice coding!
HackerRank is the best place to learn and practice coding!
When we sum the integers 4 and 12 , we get the integer 16.
When we sum the floating-point numbers 4.0 and 4.0, we get 8.0.
When we concatenate
is the best place to learn and practice coding!, we get
HackerRank is the best place to learn and practice coding!.
My solution in Ruby:
# Declare second integer, double, and String variables.
# Read and save an integer, double, and String to your variables.
i2 = gets.to_i
d2 = gets.to_f
s2 = gets.to_s
# Print the sum of both integer variables on a new line.
puts (i + i2)
# Print the sum of the double variables on a new line.
puts (d + d2)
# Concatenate and print the String variables on a new line
# The ‘s’ variable above should be printed first.
puts (s + s2)