Menu
Question Index
...


Write a program to get all possibilities for stretching a word to the given size. The possibilities returned should be sorted. If the list of required indices is passed, then only those combinations present at those indices should be returned. If the required indices are null, then all the combinations have to be returned.

Input (String, int, int[]) Output (List)
1234, 6, null [111234, 112234, 112334, 112344, 122234, 122334, 122344, 123334, 123344, 123444]
1234, 6, [1, 5, 9] [112234, 122334, 123444]
1234, 5, null [11234, 12234, 12334, 12344]
merit, 6, null [meerit, meriit, meritt, merrit, mmerit]
merit, 6, [0, 4] [meerit, mmerit]
ABCD, 6, null [AAABCD, AABBCD, AABCCD, AABCDD, ABBBCD, ABBCCD, ABBCDD, ABCCCD, ABCCDD, ABCDDD]
ABCD, 6, [1, 3, 7, 8] [AABBCD, AABCDD, ABCCCD, ABCCDD]
PROGRAM, 5, null []
JAVA, 4, null [JAVA]
FIVE, -1, null []

class RubberbandWord

{    public static void main(String s[])
    {
        System.out.println(stretchWords("TOPCODER", 10, null));

    }


public static List<String> stretchWords(String word, int requiredLength, int[] requestedIndices) {
//Write code here to get all the possible combinations for stretching the word to the given length
}

//If required, write any additional methods here
}

Doubts

Problems

Topic: Java ArrayList

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App