DDSA Solutions

1967. Number of Strings That Appear as Substrings in Word

Time: O(p * n)
Space: O(1)

Problem Overview

Number of Strings That Appear as Substrings in Word (Unknown) asks you to solve a structured algorithmic task. This is a common String pattern in coding interviews. Count patterns where word.Contains(pattern) is true.

A full step-by-step explanation is being added. See the study guide for pattern-based practice.

Approach

Count patterns where word.Contains(pattern) is true.

Related patterns: String

1967.cs
C#
// Approach: Count patterns where word.Contains(pattern) is true.
// Time: O(p * n) Space: O(1)

public class Solution
{
    public int NumOfStrings(string[] patterns, string word)
    {
        return patterns.Count(pattern => word.Contains(pattern));
    }
}
Was this solution helpful?

Related Problems