FastPrepImplement Substring Search
Problems/Implement Substring Search

Implement Substring Search

IMC Trading logoIMC Trading● MediumINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an IMC Trading phone screen for an intern role. Our version is about 75% the same as the named interview problem. The report gives only strstr. This version says what to return for the first index and for a missing or empty needle, uses lowercase input, and sets limits on the numbers.

Given text and pattern, return the zero-based index of the first occurrence of pattern as a contiguous substring of text.

Return -1 when the pattern does not occur. An empty pattern returns 0, including when the text is empty.

Function

strStr(text: String, pattern: String) → int

Examples

Example 1

text = "mississippi"pattern = "issip"return = 4

Return the zero-based first matching position. The empty pattern occurs at index 0.

Example 2

text = "abc"pattern = "d"return = -1

Return the zero-based first matching position. The empty pattern occurs at index 0.

Example 3

text = "abc"pattern = ""return = 0

Return the zero-based first matching position. The empty pattern occurs at index 0.

Constraints

  • 0 <= text.length, pattern.length <= 10^6
  • Both strings contain only lowercase English letters.

More IMC Trading Phone Screen questions

  • Election District Budget Allocation AnalysisPHONE SCREEN · Seen Aug 2026
  • Uniform Variables: Smaller Below Larger SquaredPHONE SCREEN · Seen Mar 2026
  • Combination Sum with Unlimited ReusePHONE SCREEN · Seen Dec 2025
  • Valid Range of a Three-Outcome Probability ParameterPHONE SCREEN · Seen Dec 2025
  • Expected Fishing CatchPHONE SCREEN · Seen Dec 2025
  • Count Routes Through a City GridPHONE SCREEN · Seen Nov 2024
  • Expected City Arrival and Return DaysPHONE SCREEN · Seen Nov 2024
  • Stationary City Population SharesPHONE SCREEN · Seen Nov 2024
  • Maximum Falling Path SumPHONE SCREEN · Seen Nov 2024
  • Trading Profit Percentage ChangePHONE SCREEN · Seen Feb 2024

Similar questions at other companies

  • Classify Password StrengthHackerRank · OA · PHONE SCREEN · ONSITE INTERVIEWHackerRank interview questions
  • Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEWDuolingo interview questions
  • Route Pattern MatcherGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Dasher Pay with Store Waits and Peak HoursDoorDash · PHONE SCREENDoorDash interview questions
  • Fuzzy Word Lookup With One Misspelled LetterMeta · PHONE SCREENMeta interview questions
  • Most Frequent Call Path From Function Trace LogsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Minimum Number of Frogs CroakingCerebras · PHONE SCREEN
  • Adjacent Pair and Run RemovalWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions

IMC Trading interview experiences

  • IMC Trading OA: What It Tests (2026)
  • IMC Trading SWE OA and Video: 18 Experiences (Part 3 of 3)
  • IMC Trading SWE OA Questions: 22 Experiences (Part 2 of 3)
  • IMC SWE New Grad OA and Interviews: 58 Experiences (Part 1 of 3)
All IMC Trading interview questionsSee IMC Trading hiring insights
Saved
class Solution {
    public int strStr(String text, String pattern) {
        // Write your solution here.
    }
}
Checking account…