BackmediumStrings Swiggy

Asteroid Signal Detection Solution

Problem Statement

Given a string of space signals and a specific asteroid signal pattern, identify all occurrences of the pattern as a substring and return the count of how many times this pattern appears in the given string, considering overlaps are allowed.

Example 1
Input
101010101
Output
6

Explanation: Step-by-step: The pattern '10' appears 6 times in the string '101010101'. We can see this by counting the occurrences of '10' in the string: '10' appears at indices 0, 2, 4, 6, 8, and 10, giving a total of 6 occurrences.

Example 2
Input
111111
Output
6

Explanation: Step-by-step: The pattern '1' appears 6 times in the string '111111'. We can see this by counting the occurrences of '1' in the string: '1' appears at indices 0, 1, 2, 3, 4, and 5, giving a total of 6 occurrences.

Constraints

  • 1 <= length of signal string <= 10^5
  • 1 <= length of pattern <= 100
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free