Guys , try this if you have the time.
------------------------------------------
Children are used to playing with special cubes with letters written on the cubes' faces. The goal of the game is to compose words using such cubes. If you want to compose the word "DOG", you must find 3 cubes, one containing the letter 'D', one containing the letter 'O', and one containing the letter 'G', and orient them so the proper letters are facing upward.
You are also given a String[] words, each element of which contains a word that you would like to spell out using the cubes. Return a int[] containing the 0-based indices of each of the words in words that can be composed using the given cubes. Indices in the return value must be sorted in ascending order.
Question :-
To compose the function
int[] composeWords(String[] cubes, String[] words)
Example Output :-
0)
{"ABCDEF", "DEFGHI", "OPQRST", "ZZZZZZ", "YYYYYY"}
{"CAT", "DOG", "PIZZA"}
composeWords Returns: {1 }
We can form the word "DOG" using 'D' from the first cube, 'O' from the third and 'G' from the second. Note that if we had used the second cube to get 'D' instead, we would be missing a 'G'.
1)
{"ABCDEF", "DEFGHI", "OPQRST", "MNZLSA", "QEIOGH", "IARJGS"}
{"DOG", "CAT", "MOUSE", "BIRD", "CHICKEN", "PIG", "ANIMAL"}
composeWords Returns: {0, 1, 3, 5 }
2)
{"AAAAAA", "AAAAAA", "AAAAAA", "AAAAAA"}
{"AA", "AAA", "AAAA", "AAAAA", "AAAAAA"}
composeWords Returns: {0, 1, 2 }
3)
{"ABCDEF", "DEFGHI", "OPQRST", "ZZZZZZ", "ZZZZZZ"}
{"CAT", "DOG", "PIZZA"}
composeWords Returns: {1, 2 }
No comments:
Post a Comment