Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6058427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:35:54+00:00 2026-05-23T08:35:54+00:00

I had an interview question asking this: text file has following lines> 1: A

  • 0

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 language

of your choice that outputs a sorted
list like

            A: 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:35:54+00:00Added an answer on May 23, 2026 at 8:35 am

    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:

     string inp = @"1: A C D
                4: A B
                5: D F
                7: A E
                9: B C";
                Dictionary<string, List<int>> res = new Dictionary<string, List<int>>();
                StringReader sr = new StringReader(inp);
                string line;
                while (null != (line = sr.ReadLine()))
                {
                    if (!string.IsNullOrEmpty(line))
                    {
                        string[] tokens = line.Split(": ".ToArray(),StringSplitOptions.RemoveEmptyEntries);
                        int idx = int.Parse(tokens[0]);
                        for (int i = 1; i < tokens.Length; ++i)
                        {
                            if (!res.ContainsKey(tokens[i]))
                                res[tokens[i]] = new List<int>();
                            res[tokens[i]].Add(int.Parse(tokens[0]));
                        }
                    }
                }
    

    res will contain the result of letter->list of numbers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Had the following as an interview question a while ago and choked so bad
This is one of an interview question which I had recently. I would like
I had an interview days ago and was thrown a question like this. Q:
I had a recursion interview question problem in Java,Need your help on this. Write
I had a following interview question. There is an array of nxn elements. The
In an interview they had asked an Question like this there are three overloading
I recently had this question in an interview to write test cases to test
I had telephone interview question yesterday. The interviewer asked me if I had faced
I had an interview question that asked me for my 'feedback' on a piece
Another recent C# interview question I had was if I knew what Boxing and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.