Amazon Interview Report
- 2of 2 votes
AnswersLucky numbers are those numbers which contain only "4" and/or "5". For example 4, 5, 44, 54,55,444 are lucky numbers while 457, 987 ,154 are not.
- sunny.010203045 January 29, 2014 in India
Lucky number sequence is one in which all lucky numbers exist in increasing order for example 4,5,44,45,54,55,444,445,454,455...
Now we concatenate all the lucky numbers (in ascending order) to make a lucky string "4544455455444445454455..."
Given n, your task is to find the nth digit of the lucky string. If the digit is 4 then you have to print "Hacker" else you have to print "Earth".
Input:
first line contain number of test cases T , next T line contain a single interger n.
Output:
For each test case print "Hacker"(without quotes) if nth digit of lucky string is "4" else print "Earth"(without quotes) if nth digit of lucky string is "5".
Constraints:
1<=t<=10^5
1<=n<=10^15| Report Duplicate | Flag | PURGE
Amazon SDE1 - 1of 1 vote
AnswersProblem Statement
- sunny.010203045 January 29, 2014 in India
There are three types of tickets and stations available in CodeCountry A, B and C. Tickets of type A can only be bought at stations of type A and end at a station of type B. Tickets of type B can only be bought at stations of type B and end at a station of type C. Similarly, tickets of type C can only be bought at stations of type C and end at a station of type A. Also, you can only travel from station i to station j if j > i, i.e. you can only move forward and if the ticket type bought at station i ends at station j.
The cost of a ticket is j x j if you travel a distance of j. For example if you start at Station 3 and end at station 5 the cost is 2 x 2=4.
Now, you want to travel from Station 1 to Station N using trains in CodeCountry. You are given the type of each station. Output the minimum cost of the journey.
Note that station N will also have a type and you must reach it using a ticket of compatible type. Output -1 if it is not possible to reach from station 1 to station N
Input Format
The first line contains the number of test cases T. This is followed by T lines one for each test case.
Each test case consists of a string representing the types of each station. The i-th character of the string represents the i-th station's type.
Output Format
Output the minimum cost of the journey, one line per test case.
Constraints
The number of test cases is atmost 50.
There will be atleast 2 stations and atmost 15 stations.
The first station (station 1) is always of type A.| Report Duplicate | Flag | PURGE
Amazon SDE1