Question bank › Strings
Dsa Strings Warm-up

Pattern Matching in a Sentence

You are given a sentence and a word. Your task is to count how many times the word appears in the sentence and return the positions of those appearances (0-based index). If the word does not appear, return -1. The inputs will be provided as a single line where the first part is the sentence followed by the word, separated by a comma. Example Input: This is a test sentence, test Example Output: 2 0,10

Key concepts

stringssearchindexing

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.