r/dailyprogrammer_ideas • • Nov 11 '17

Minimizing Time[Intermediate]

Reddit wants to add a new feature on their website to help the searching process. They want to add a new keyboard to type strings in minimum time. They hired you as developer and explained the problem to you. You are given a string to type and you need to design a keyboard such that the total time taken to type the string is minimised.

The keyboard consists of 3 rows and 21 columns i.e 63 keys.These 63 keys include all the 26 lowercase alphabets, 26 uppercase alphabets, 10 numeric keys and 1 key for space.

If you are at the key (x,y) and you want to press the key at position (z,w) then the time taken will be abs(x−z)+abs(w−y)

NOTE: Initially your finger is at (1,1).

Input

There is only one line of input that corresponds to the sentence X that is to be typed. X may contain spaces in between

Output

In the output you need to provide a matrix of size 3×21 that corresponds to the size of the keyboard that is to be formed. There should not be any key repeated and all the 63 symbols should be there. For space you need to output .(dot).

Constraints

Length of string X= 105 for all the test cases.

Scoring Suppose that the time taken to type the sentence is T then your score will be T and your aim should be to minimise this score

4 Upvotes

2 comments sorted by

View all comments

Show parent comment

1

u/mn-haskell-guy Nov 13 '17

In the abracadabra case, since there are only 5 distinct letters you can decide whether you are allowed to repeat letters on the keyboard or if one of the keys (on a 2x3 keyboard) will remain unassigned.