Check whether a word appears as a whole word in a paragraph, ignoring case

Quick Overview

Decide whether a word appears in a paragraph as a whole word, ignoring case, where only English letters form words and every other character separates them. It tests careful string scanning, case handling, and boundary cases such as punctuation next to the word or the word hidden inside a longer one.

Check whether a word appears as a whole word in a paragraph, ignoring case

Company: Algolia

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

Given a string `paragraph` and a string `word`, determine whether `word` appears in `paragraph` as a whole word. An occurrence counts as a whole word when the character on each side of it is a non-letter (a space or punctuation) or the start or end of the string. The comparison is case-insensitive. Return `True` if at least one whole-word occurrence exists and `False` otherwise. ### Function Signature ```python def is_word_present(paragraph: str, word: str) -> bool: ``` ### Rules - Only the English letters `A-Z` and `a-z` count as letters. Every other character, including apostrophes and hyphens, separates words, so "fox" is found in "fox's" and in "fox-like". - `word` is a single word made only of English letters. - An occurrence inside a longer run of letters does not count, so "fox" is not found in "foxes". ### Constraints - `1 <= len(paragraph) <= 1000` - `1 <= len(word) <= 50` - `paragraph` consists of English letters, spaces, and punctuation characters. - `word` consists of English letters. ### Examples ```text Input: paragraph = "The quick brown fox jumps over the lazy dog.", word = "fox" Output: True ``` "fox" sits between two spaces, so it is a whole word. ```text Input: paragraph = "Hello, world! Hello again.", word = "HELLO" Output: True ``` "Hello" at the start of the paragraph is followed by a comma, and it equals "HELLO" once case is ignored. ```text Input: paragraph = "The foxes outfoxed the hounds.", word = "fox" Output: False ``` The letters "fox" appear twice, but both times inside a longer word ("foxes" and "outfoxed"), with a letter right next to them.

Overview: Decide whether a word appears in a paragraph as a whole word, ignoring case, where only English letters form words and every other character separates them. It tests careful string scanning, case handling, and boundary cases such as punctuation next to the word or the word hidden inside a longer one.

Algolia logo
Algolia
Nov 24, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Given a string paragraph and a string word, determine whether word appears in paragraph as a whole word.

An occurrence counts as a whole word when the character on each side of it is a non-letter (a space or punctuation) or the start or end of the string. The comparison is case-insensitive. Return True if at least one whole-word occurrence exists and False otherwise.

Function Signature

def is_word_present(paragraph: str, word: str) -> bool:

Rules

  • Only the English letters A-Z and a-z count as letters. Every other character, including apostrophes and hyphens, separates words, so "fox" is found in "fox's" and in "fox-like".
  • word is a single word made only of English letters.
  • An occurrence inside a longer run of letters does not count, so "fox" is not found in "foxes".

Constraints

  • 1 <= len(paragraph) <= 1000
  • 1 <= len(word) <= 50
  • paragraph consists of English letters, spaces, and punctuation characters.
  • word consists of English letters.

Examples

Input: paragraph = "The quick brown fox jumps over the lazy dog.", word = "fox"
Output: True

"fox" sits between two spaces, so it is a whole word.

Input: paragraph = "Hello, world! Hello again.", word = "HELLO"
Output: True

"Hello" at the start of the paragraph is followed by a comma, and it equals "HELLO" once case is ignored.

Input: paragraph = "The foxes outfoxed the hounds.", word = "fox"
Output: False

The letters "fox" appear twice, but both times inside a longer word ("foxes" and "outfoxed"), with a letter right next to them.