If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

Verifying an algorithm


The goal of the procedure longestWord is to return the longest word in a given list of words. For example, if it's given the list ["superhero", "captain", "marvel"], it should return "superhero" as the longest word.
PROCEDURE longestWord(words) {
    maxWordLen ← 0
    maxWord ← ""
    FOR word IN words {
        IF (LENGTH(word) > maxWordLen) {
           maxWord ← word
           maxWordLen ← LENGTH(word)
           RETURN maxWord
    RETURN maxWord
A programmer tests the procedure with various inputs and finds that there are multiple cases where it does not produce the expected output.
Which calls to longestWord() do not actually return the longest word?
👁️Note that there are 2 answers to this question.
Choose 2 answers: