Statistics

Problem Statement for "SpellBee"

Problem Statement

PROBLEM STATEMENT

In a certain spelling bee, each contestant is given a word to spell.  If the
contestant spells it correctly, they move on to the next round.  If they don't,
however, they are eliminated from the contest entirely.  When a contestant is
spelling the word, they are allowed to start over mid-word, but they are not
allowed to change or leave out any of the letters they have already spoken;
they are only allowed to repeat their previous letter list and optionally add
one or more letters to the end of it.  Their last string of letters is the one
that is compared to the word being spelled, to determine whether or not the
contestant moves on.

For example, if the word was "horseradish", then the contestant can spell
"hors", then "horsera", then "horseradish", and move on to the next round.
However, if the contestant spelled "horsr" and then "horseradish", then the
contestant is eliminated, because the two letter lists don't agree on the fifth
letter.

Create a class SpellBee that contains the method verify, which takes the word
to be spelled (as a String) and a list of one contestant's spellings of one word.
If the contestant spells the word incorrectly, and his/her lists don't agree,
return 0.
If the contestant spells the word correctly (see the first NOTE), but his/her
lists don't agree, return 1.
If the contestant spells the word incorrectly, but his/her lists do agree,
return 2.
If the contestant spells the word correctly, and his/her lists do agree, return
3.

DEFINITION
Class: SpellBee
Method: verify
Parameters: String, String[]
Returns: int
Method signature (be sure your method is public):  int verify(String word,
String[] spellings);

NOTES
- The contestant has spelled the word correctly if and only if the last element
in spellings matches word exactly.
- The contestant's letter lists agree if and only if each element in spellings
after the first element begins with the previous element in spellings.
- Assume that with each new element in spellings, the contestant is starting
the word over.  That is, do not check to see if adjacent elements form words.

TopCoder will ensure the validity of the inputs.  Inputs are valid if all of
the following criteria are met:
- word and every element in spellings will consist only of lower-case letters
('a'-'z').
- word contains between 1 and 20 characters, inclusive.
- spellings contains between 1 and 10 elements, inclusive.
- Each element in spellings contains between 1 and 20 characters, inclusive.
	
EXAMPLES

Example 1:
word = "migraine"
spellings = {"m", "migr", "migr", "migrain"}
The letter lists do agree, but the contestant misspelled "migraine", so the
method returns 2.

Example 2:
word = "apricot"
spellings = {"aprico", "apricot"}
The method returns 3.

Example 3:
word = "hippopotamus"
spellings = {"hipo", "hippopot", "hippopotamus"}
The method returns 1.

Example 4:
word = "hippopotamus"
spellings = {"hippopotamus", "hippopot", "hip"}
The method returns 0.

Example 5:
word = "embroider"
spellings = {"embroy", "embroidur"}
The method returns 0.

Example 6:
word = "abcdefghijklmnopqrst"
spellings = {"abcdefghijklmnopqrst"}
The method returns 3.

Example 7:
word = "word"
spellings = {"totally", "totallydifferent", "totallydifferentword"}
The method returns 2.

Definition

Class:
SpellBee
Method:
verify
Parameters:
String, String[]
Returns:
int
Method signature:
int verify(String param0, String[] param1)
(be sure your method is public)

Constraints

    Examples


      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: