Statistics

Problem Statement for "Thesaurus"

Problem Statement

An entry in a Thesaurus is a list of words that are all synonyms. Each entry contains no duplicates within it. It is possible that two entries might have some common words, but the editors (who are somewhat cheap) have decided that if any two entries have 2 or more words in common then they should be combined into a single entry.

This editing process may produce new entries which can be combined. The final Thesaurus must contain no pair of entries that have 2 or more words in common. Of course, each entry must contain no duplicates.

Create a class Thesaurus that contains a method edit that is given a String[] entry, the entries in the original Thesaurus. The method returns the edited Thesaurus as a String[]. Each element of entry has no leading or trailing spaces and has its words separated by a single space. Each element of the return should also have no leading or trailing spaces and have its words separated by a single space. In addition, the words within each element of the return must be in alphabetical order, and the elements in the return must appear in alphabetical order.

Definition

Class:
Thesaurus
Method:
edit
Parameters:
String[]
Returns:
String[]
Method signature:
String[] edit(String[] entry)
(be sure your method is public)

Constraints

  • entry will contain between 1 and 50 elements inclusive.
  • Each element of entry will contain between 1 and 50 characters inclusive.
  • Each element of entry will consist of 1 or more "words" separated by single spaces.
  • Each element of entry will contain no leading or trailing spaces.
  • Each "word" will consist of 1 or more lowercase letters 'a'-'z'
  • No element of entry will contain two identical words.

Examples

  1. {"ape monkey wrench", "wrench twist strain"}

    Returns: { "ape monkey wrench", "strain twist wrench" }

    These two entries have only one common word so they cannot be combined. After rearranging the words within each entry to put the words into alphabetical order, the first entry is first alphabetically.

  2. {"ape monkey wrench", "wrench twist strain", "monkey twist frugue"}

    Returns: { "ape monkey wrench", "frugue monkey twist", "strain twist wrench" }

    No entries could be combined, but two had to be arranged, and the order was changed.

  3. {"ape monkey wrench", "wrench twist strain", "monkey twist frugue strain"}

    Returns: { "ape frugue monkey strain twist wrench" }

    The first two entries could not be combined, but the last two could. After they were combined, the first entry shared both "wrench" and "monkey" with the new combined entry, so we ended up with just one entry.

  4. {"a"}

    Returns: { "a" }

  5. {"c b a","a b c","c d","d e","e d b"}

    Returns: { "a b c", "b d e", "c d" }

  6. {"point run score","point dot","cut run tear score","cut valley","cute pretty"}

    Returns: { "cut point run score tear", "cut valley", "cute pretty", "dot point" }

  7. {"a b c","d e f", "g h i", "b g c e f"}

    Returns: { "a b c d e f g", "g h i" }

  8. {"d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g","d o u g"}

    Returns: { "d g o u" }

  9. {"a b c d e f g h i j k l m n o p q r s t u v w x y","a z","b c bob","tom x k","a z"}

    Returns: { "a b bob c d e f g h i j k l m n o p q r s t tom u v w x y", "a z" }

  10. {"asdladkljfhafakjhfdsakadslksdakfadslkhdah a","afdsakjfhdsafsakasddsf"}

    Returns: { "a asdladkljfhafakjhfdsakadslksdakfadslkhdah", "afdsakjfhdsafsakasddsf" }

  11. {"a b x","h z x", "k l m","h a t","x t a"}

    Returns: { "a b h t x z", "k l m" }

  12. {"a aa aaa aaaa","aaaaa aaa a", "aa aaaaaa"}

    Returns: { "a aa aaa aaaa aaaaa", "aa aaaaaa" }

  13. {"abc cba bac","abc cab acb"}

    Returns: { "abc acb cab", "abc bac cba" }

  14. {"bob tom joe cal","tom tim eve jed","jed dj jd bob"}

    Returns: { "bob cal joe tom", "bob dj jd jed", "eve jed tim tom" }

  15. {"all every many lots", "lots parcels estates grounds", "grounds"}

    Returns: { "all every lots many", "estates grounds lots parcels", "grounds" }

  16. { "a b c d e f g h i j k l m n o p q r s t u v w x y", "z aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo at", "z pp qq rr ss tt uu vv ww xx yy zz aa tr rt op po", "this is a test whee hehehehehehehehhehehehheheheh", "test abcdefghijklmnopqrstuvwxyz x z ppppppppppppp", "hehehhehehehehehhehehhehehhhhheheh mpmpmpmpmpmpmp", "tt rrrrrrrrrrrrrrrrrrrr sssssssssssssss ssssssssss", "lllllll llllllll llllllllz lllllllll pppppppppppp", "aa nn dd a b test mmmmmmmmmmmmmmmmmmmmmmmmmm yyyyy", "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz zzzzzzz", "a d c o p m n r e at oo test rrrrrrrrrr rrrrrrrrr", "yyyyyyyyyyyyyyyyy yyyyyyyyyyyyyy yyyyyyy yyy y at", "ab ba ca ac tj jt lm ml no on er re qw wq tr rt yu", "uy cv vc zx xz sa as ks sk md dm pz zp cp at test", "xp px pc cp gt tg yh hy jy yj ki ik po lm nb bn", "vb bv xe ex bbbbbbbbbbbbbb nnnnnnnnnnnn oooooooooo", "slkfjsl lskfjdlsk oitporit aslkfjsldk ncnsjlkfs aa", "tirutoi reoiuksldf slkdjfls calskdfj slkdfj eeeeee", "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", "yyyy mmmm wwww llll eeee qqqq aaaa vvvv cccc rrrrr", "la al mc cm zx xm mx re tr yr ur ir or pr fd df gh", "ffffffffff nnnnnnnn ooooooooo kkkkkkkkk jjjjjjjjjj", "wwwwweeeeeeeee ewwwwwwwweweweewew eeeeeeeeeee aaaa", "aa b c d e f g h i j k l m n o p q r ss u v w x y", "bbbbbbbbbbbbbbbbb vvvvvvvvvvvvvvv eeeeeeeee aaaaaa", "z aa bb cc dd ee ff gg hh ii jj kk ll mm nn zz at", "c cc qq rr ss tt uu vv ww xx yy w aa tr rt op po", "qwerty qwertp qwertyy qwertya qwertyb qwertyn mmmk", "hhhhhhhhhhhhhhh hhhhhhhhhhhhhhhhhhhhhhhh fffffffff", "f ff gg cc dd ee re ta hh ii jj kk ll mm lk ok at", "y uu gg jh dd nv re ta hh hj yy kk ll mm lk ok at", "q qq jn oc dd ee co ta hh ii jj kk ll nj lk ok b", "z hg gh cc cx ee ff iy hh ii jj kk ll mm yi lj at", "t ty bb yw dd yt ff rr hh hy yh df fd as sa oo at", "ppppppppppppppppppppwwwwwwwwwwwwwwwwwwwwwwwwwwwwww", "mnmnmnmnmnm nmnmnmnmnmnm nnnmnmnmnmnm mnmnmmmmnmn", "z b a e p o l mm ee tt fffg gg hj jh lk kl mmmmm", "pppp rere erer u z c v j k l m w r q d f g test", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa z", "gggggggg uuuuuuuuuuuuuuu pppppppp rrrrrrrrrrrrrrr", "slfk slkd xzmc pewir skdf alskd hdfkj whekj sd ds", "ds n m k pp rr tt ss zz xx aa ww qq qqqq ffff lklk", "pipopppipo lskjflks rueyreu wtewyet w s a z f d h", "pw wp re er tr rt yg gy br rb vd dv sc cs as sa qa", "aq mz zm yu hg bf dv sm ls kd sv cu yhf sgd ldf t", "m n o p q r s t u v w x y z aa bb cc dd ee ff gg h", "gg hh ii jj kk ll tt uu vv ww xx yy zz aa ki ik", "po lm nb d e f g h i j k l m n o p q r s t u v w a", "px pc cp gt tg yh hy jy yj ki d e f g h i v w x y", "ab ba ca ac tj jt lm ml no on er re qw wq tr rt yy" }

    Returns: { "a aa ab abcdefghijklmnopqrstuvwxyz ac al aq as at b ba bb bf bn br c ca cc cm co cp cs cu cv cx d dd df dm ds dv e ee er erer f fd ff ffff fffg g gg gh gt gy h hehehehehehehehhehehehheheheh hg hh hj hy i ii ik ir is iy j jh jj jn jt jy k kd ki kk kl ks l la ldf lj lk lklk ll lm ls lskjflks m mc md ml mm mmmmm mmmmmmmmmmmmmmmmmmmmmmmmmm mx mz n nb nj nn no nv o oc ok on oo op or p pc pipopppipo po pp pppp ppppppppppppp pr pw px pz q qa qq qqqq qw r rb re rere rr rrrrrrrrr rrrrrrrrrr rt rueyreu s sa sc sgd sk sm ss sv t ta test tg this tj tr tt ty u ur uu uy v vc vd vv w whee wp wq wtewyet ww x xm xp xx xz y yg yh yhf yi yj yr yt yu yw yy yyy yyyyy yyyyyyy yyyyyyyyyyyyyy yyyyyyyyyyyyyyyyy z zm zp zx zz", "aa aslkfjsldk lskfjdlsk ncnsjlkfs oitporit slkfjsl", "aaaa cccc eeee llll mmmm qqqq rrrrr vvvv wwww yyyy", "aaaa eeeeeeeeeee ewwwwwwwweweweewew wwwwweeeeeeeee", "aaaaaa bbbbbbbbbbbbbbbbb eeeeeeeee vvvvvvvvvvvvvvv", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa z", "alskd ds hdfkj pewir sd skdf slfk slkd whekj xzmc", "bbbbbbbbbbbbbb bv ex nnnnnnnnnnnn oooooooooo vb xe", "calskdfj eeeeee reoiuksldf slkdfj slkdjfls tirutoi", "fffffffff hhhhhhhhhhhhhhh hhhhhhhhhhhhhhhhhhhhhhhh", "ffffffffff jjjjjjjjjj kkkkkkkkk nnnnnnnn ooooooooo", "gggggggg pppppppp rrrrrrrrrrrrrrr uuuuuuuuuuuuuuu", "hehehhehehehehehhehehhehehhhhheheh mpmpmpmpmpmpmp", "lllllll llllllll lllllllll llllllllz pppppppppppp", "mmmk qwertp qwerty qwertya qwertyb qwertyn qwertyy", "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", "mnmnmmmmnmn mnmnmnmnmnm nmnmnmnmnmnm nnnmnmnmnmnm", "ppppppppppppppppppppwwwwwwwwwwwwwwwwwwwwwwwwwwwwww", "rrrrrrrrrrrrrrrrrrrr ssssssssss sssssssssssssss tt", "zzzzzzz zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" }

  17. { "ape monkey wrench", "wrench twist strain", "monkey twist frugue strain" }

    Returns: { "ape frugue monkey strain twist wrench" }

  18. { "a b", "b c", "c d", "d a", "aa", "aaa", "da" }

    Returns: { "a b", "a d", "aa", "aaa", "b c", "c d", "da" }

  19. { "a aa aaa", "a aaa", "aa aaa", "a aa aaaa", "aaaa", "a" }

    Returns: { "a", "a aa aaa aaaa", "aaaa" }

  20. { "a", "a" }

    Returns: { "a", "a" }

  21. { "abc def ghi", "abc def", "abc efg hui" }

    Returns: { "abc def ghi", "abc efg hui" }


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: