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

  • SEARCH
  • Home
  • 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 7879459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:54:10+00:00 2026-06-03T03:54:10+00:00

I was asked this question in an interview. Suppose you have an ordered dictionary,

  • 0

I was asked this question in an interview. Suppose you have an ordered dictionary, and are given a list of unordered characters- how would you order these characters by precedence? This dictionary contains words where all the 26 characters are guaranteed to appear. However, note that the size of the dictionary might be anything. The dictionary could be as small as a few words and may not have separate sections for each character e.g., there might be no sections for words beginning with a; although a will appear as part of another word e.g., “bat”.

The dictionary might be “ordered” (/sarcasm) as such “zebra’, “apple”, “cat”, “crass”, and if you’re given the list {a, z, r}, the correct order would be {z, a, r}. Since “zebra” is before “apple” in the dictionary, we know z comes before a in the presedence. Since “apple” comes before “cat”, we know a comes before c. Since “cat” comes before “crass”, we know that a comes before r. This ordering leaves c and r with ambugious presendece, but since the list of letters was {a, z, r}, we know the solution to be {z, a, r}.

  • 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-06-03T03:54:11+00:00Added an answer on June 3, 2026 at 3:54 am

    Use a directed graph with 26 vertices, each vertex represents a character. An edge from vertex A to vertex B means in the alphabet B is in front of A.

    The first step is to establish such a graph with only vertices but NO edges.

    Second, you scan the input dictionary, word by word. And compare each word with the previous word. You should find exact one relationship for each word you scanned. So you add an edge in this graph. Assume the dictionary is correct, there should be no conflicts.

    After you finished the dictionary, you output the alphabet by

    1. pick a random vertex, traverse its path until you find the one character that points to nothing. This is the first character in the alphabet. Output it and delete it from the graph.
    2. keep doing 1 until all vertices are deleted.

    EDIT:
    To better explain this algorithm, let’s run it on your sample input.

    Input: {“zebra’, “apple”, “cat”, “crass”}

    Word 0 and word 1, we immediately know that z comes before a, so we make an edge a->z

    Word 1 and word 2, we immediately know that a comes before c, so we make another edge c->a

    Word 2 and Word 3, the first letters are the same “c”, but the second ones differ, so we learn that a comes before r, so we have another edge r->a

    Now all the words are read. Output the order by pick up a vertex randomly (say we pick c), then we have c->a->z in the graph. Output z and delete z from the graph (mark it as NULL). Now pick another one (say we pick r), then we find r->a in the graph. We output a and delete a from graph. Now we pick another one (say we pick c again), there’s no path found, so we just output c and delete it. Now we pick the last one, r, there’s no path again, so we output r and delete it. Since all vertices are deleted, the algorithm is done.

    The output is z, a, c, r. The ordering of “c” and “r” are random since we don’t really know their relationship from the input.

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

Sidebar

Related Questions

This question was asked in interview and deals with recursion/backtracking. Suppose we have two
I went to an interview today and was asked this question: Suppose you have
I have a question. I was once asked this in the interview -- Suppose
This question was asked to me in an interview. Suppose char *p=malloc(n) assigns more
This question was asked at interview. Say I have a contract. [ServiceContract] public interface
Interview Question I have been asked this question in an interview, and the answer
I was asked this question in an interview would appreciate your answers. Regards; Mohammad
I have been asked this question in interview how does XML and Soap work
I was asked this question during phone interview. Given two strings find the minimal
I was asked this question in a .net/C# interview: If we have two threads

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.