HackerRank : RookieRank 3 – Comparing Times

By | May 6, 2017
Comparing Times : Hackerrank

Given two times, and , in the 12-hour AM/PM format, we want to know which time occurs first during a day. For example, if is 08:02PM and is 06:51AM, then occurs before .

Solve queries where each query consists of some and . For each query, print First if occurs before ; otherwise, print Second.

Note: The day starts at 12:00AM (midnight) and ends at 11:59PM. The time 12:00PM denotes noon (midday).

Input Format

The first line contains an integer denoting (the number of queries).
Each of the subsequent lines contains two space-separated strings describing the respective values of and .

Constraints

Output Format

For each query, print First if occurs before ; otherwise, print Second.

Note: If using the given code stubs, complete the function so that it returns the appropriate string.

Sample Input 0

2
10:19PM 02:49AM
08:49AM 09:10AM

Sample Output 0

Second
First

Explanation 0

We perform the following queries:

  1. is 10:19PM and is 02:49AM. Because AM always occurs before PM, we know that occurs earlier and we print Second.
  2. is 08:49AM and is 09:10AM. Both times occur during the AM (first half of the day), so we compare their hours. Because , we know that occurs earlier and we print First.

Solution

Hint: I have used Date util in Java. 
There are three conditions to check. one results in "First", one in "Second" 
straight away.
And third condition needs a comparison actually.