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

Jeżeli jesteś za filtrem sieci web, prosimy, upewnij się, że domeny *.kastatic.org i *.kasandbox.org są odblokowane.

Główna zawartość

Weryfikacja algorytmu


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.
Wybierz 2 odpowiedzi:
Nie wiesz, jak rozwiązać to zadanie?
Nie wiesz, jak rozwiązać to zadanie?