Skip to content

Instantly share code, notes, and snippets.

@brijeshb42
Created July 7, 2013 09:23
Show Gist options
  • Save brijeshb42/5942910 to your computer and use it in GitHub Desktop.
Save brijeshb42/5942910 to your computer and use it in GitHub Desktop.
FB Interview
You are given an input of dictionary followed by some words that use a secret dictionary. Because each word in the line shares some letters with other words, you can descramble it by figuring out which words they must be to use the same secret code. Note that each secret line can use it's own dictionary.
Testcases format:
The input contains a single integer N (<100) followed by N words in the dictionary
This is followed by an integer K (< 100)following which there are K alphanumeric words belonging to the secret dictionary. The maximum length of each word would be 1024 characters
Output the decoded string one per line
The input is from stdin and output to stdout
Sample Testcases
Input #00:
4
hello
there
yello
thorns
2
12334 51272
12334 514678
Output #00:
hello there
hello thorns
Explanation:
Each secret word can use it's own dictionary. In the first case 7=r, and in the second 6=r
Input #01:
13
hello
there
yello
bob
tom
mabel
says
hi
secret
the
is
to
smile
3
45161 01223
x2x 3453 6k
x8z yz67zx 5y x4 y352z
Output #01:
there yello
bob says hi
the secret is to smile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment