Skip to main content
Back to problems
Leetcode
Easy
Functions
Strings
Hash Maps
To Be Or Not To Be

Design a small API that stores a string and answers simple queries about it.

Acceptance 0%
Problem Statement

Problem

Implement a tiny text utility that supports a few operations over an internal string value.

You will define a class-like object with methods that let a caller:

  • create the object with an initial string,
  • update the stored string,
  • compare the stored string against another string,
  • and check whether the stored string contains a given substring.

The goal is to keep the interface simple and make each operation return a boolean result when appropriate.

Notes

  • Comparison should be exact and case-sensitive.
  • Substring checks should also be exact and case-sensitive.
  • If the stored string is changed, later queries should use the updated value.

Input Format

The input is represented by method calls on a text utility object:

  • initialize with one string,
  • update the stored string with another string,
  • query equality against a provided string,
  • query whether a provided substring exists inside the stored string.

Because this is a design-style problem, there is no single standalone input format.

Output Format

For query methods, return a boolean indicating whether the condition is satisfied.

  • Equality query: true if the stored string exactly matches the provided string.
  • Substring query: true if the provided substring appears anywhere in the stored string.

Update methods do not return a value.

Constraints

  • Strings may be empty.
  • All comparisons are case-sensitive.
  • Use straightforward string operations; no special normalization is required.
  • Exact limits are not specified in the source context.
Examples
Sample cases returned by the problem API.

Example 1

Input

Initialize with `"hello"`.

Query equality with `"hello"`.
Query substring with `"ell"`.
Update the stored string to `"world"`.
Query equality with `"hello"`.
Query substring with `"or"`.

Output

true
true
false
true

Explanation

The first string matches exactly, and it contains "ell". After updating to "world", equality with "hello" becomes false, but "or" is still present.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.