I had an interview question asking this:
text file has following lines>
1: A C D 4: A B 5: D F 7: A E 9: B C*Every line has a unique integer followed by a colon and one or
more letters. These letters are
delimited spaces (one or more)>#2 Write a short program in the languageof your choice that outputs a sorted
list likeA: 1 4 7 B: 4 9 C: 1 9 D: 1 5 E: 7 F: 5
I’m not looking for someone to solve it, but I always get confused with problems like this. I’d like to do it in C# and was wondering should I store each line in a 2d array? What is the best way to handle this. After storing it how do I relist each line with letters rather then numbers?
Just looking for pointers here.
I will use a
Dictionary<string,List<int>>I will read the input and add 1 into the list at keys A,C,D, A at keys A,B etc, so having the result is just a lookup by letter.So like this, in a non esoteric way:
res will contain the result of letter->list of numbers.