Menu
Question Index
...


Write a program to create the longest word garland using the given words. Word garland is something where the next word starts with last letter of the current word. The order of words in the result may vary, as long as it is equal in length it is okay.

Input (List) Output (String)
{ant, tin, nail, egg, nose, god, goe, yax, xenon, donkey, yaz} antinoseggodonkeyaxenonail
{hat, ten, hen, exit, texture, english, tap, pig, gun, next} englishatenextexturexitapigun
{goal, apple, eagle, banana, cork, slow, test, egg, kit, kitchen} bananappleagleggoal
{malayalam, maximum, nose, mom, minimum} minimumalayalamaximumom

class LongestWordGarland

{    public static void main(String s[])
    {
        List input = new ArrayList();
        input.add("ant");
        input.add("tin");
        input.add("nail");
        input.add("egg");
        input.add("nose");
        input.add("god");
        input.add("goe");
        input.add("yax");
        input.add("xenon");
        input.add("donkey");
        input.add("yaz");
        System.out.println("The longest word garland is: " + getLongestWordGarland(input));

    }


public static String getLongestWordGarland(List<String> input) {
//Write code here to get longest word garland.
}

//If required, write any additional methods here
}

Doubts

Problems

Topic: Collection Framework In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App