Find Sliding-Window Pattern Start Indices
Updated
Problem statement
You are given a lowercase string sequence and a nonempty lowercase string pattern.
Return every zero-based index at which a contiguous window of sequence is exactly equal to pattern. Return the indices in ascending order. Overlapping matches are allowed.
Function
findPatternStartIndices(sequence: String, pattern: String) → int[]Examples
Example 1
sequence = "abracadabra"pattern = "abra"return = [0,7]The exact pattern appears at the beginning and again starting at index 7.
Example 2
sequence = "aaaa"pattern = "aa"return = [0,1,2]All three length-two windows match, including overlapping windows.
Example 3
sequence = "abc"pattern = "abcd"return = []No window is long enough to equal the pattern.
Constraints
0 <= sequence.length <= 200000.1 <= pattern.length <= 200000.- Both strings contain only lowercase English letters.
More Visa Online Assessment questions
- Count Prime Values in SubtreesOA · Seen Nov 2026
- Lock CodeOA · Seen Nov 2026
- Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
- Longest Non-Decreasing Substring After Pair SwapsOA · Seen Oct 2026
- Count Attack Vectors by Divisor RangeOA · Seen Oct 2026
- Minimum Operations to Reduce a Transaction LedgerOA · Seen Oct 2026
- Count Valid Space-Delimited WordsOA · Seen Oct 2026
- Earliest Common Meeting StartOA · Seen Oct 2026
- Maximum Index-Weighted Sum with Disjoint SwapsOA · Seen Oct 2026
- Maximum Equalized Substrings After One Adjacent SwapOA · Seen Sep 2026
Similar questions at other companies
- Incident MonitorStripe · OAStripe interview questions
- Find Word-Multiset WindowsAmazon · PHONE SCREEN
- Detect Cross-Doctor Prescription Pairs Within 30 DaysOracle · ONSITE INTERVIEWOracle interview questions
- REST API: Country CodesHackerRank · OAHackerRank interview questions
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- Count Strictly Increasing Contiguous WindowsIBM · OAIBM interview questions
- Find Words That Can Be Formed by CharactersTabaPay · OA
- Word Frequency Counts in Alphabetical OrderAbridge · OAAbridge interview questions
- Count Repeated Request IDs (Data Science OA)McKinsey & Company · OAMcKinsey & Company interview questions
- Count Multiples of Three with Two SevensHudson River Trading · OAHudson River Trading interview questions