FastPrepFind the Substring
Problems/Find the Substring

Find the Substring

LinkedIn logoLinkedIn● EasyINTERNOA

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Special thanks: Rachel shared this problem.

Given s and x, determine the zero-based index of the first occurrence of x in s.

  • String s consists of lowercase letters in the range ascii[a-z].
  • String x consists of lowercase letters and may also contain a single wildcard character, *, that represents any one character.

Function

firstOccurrence(s: String, x: String) → int

Complete the function firstOccurrence in the editor below. The function must return an integer denoting the zero-based index of the first occurrence of string x in s. If x is not in s, return -1 instead.

firstOccurrence has the following parameter(s):

  • string s: a string of lowercase letters
  • string x: a string of lowercase letters which may contain 1 instance of the wildcard character *

Examples

Example 1

s = "xabcdey"x = "ab*de"return = 1
Example 1 illustration

Constraints

  • 🧡

More LinkedIn interview questions

  • Allocate Mailboxes with Squared DistanceONSITE INTERVIEW · Seen Nov 2026
  • Find Leaves of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Max Points on a LineONSITE INTERVIEW · Seen Nov 2026
  • Maximum Product of a Contiguous SubarrayPHONE SCREEN · Seen Nov 2026
  • Maximum Sum of a Contiguous SubarrayPHONE SCREEN · Seen Nov 2026
  • Merge Two Sorted ListsPHONE SCREEN · Seen Nov 2026
  • Sqrt(x)PHONE SCREEN · Seen Nov 2026
  • Total Years of Work ExperiencePHONE SCREEN · Seen Nov 2026
  • Explore an Unknown Grid and Find a PathONSITE INTERVIEW · Seen Nov 2026
  • Fire Station Response BillONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Rearrange String by Alternating EndsHudson River Trading · OAHudson River Trading interview questions
  • Alternate String EndsCapital One · OACapital One interview questions
  • Run-Length String CompressionSalesforce · OASalesforce interview questions
  • Minimum Changes for Palindromic BlocksCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
  • Count Binary SubstringsMicrosoft · OAMicrosoft interview questions
  • Check a Repeated String as a SubsequenceQuince · OAQuince interview questions
  • Reverse String In PlaceThe Walt Disney Company · OA · PHONE SCREENThe Walt Disney Company interview questions
  • Lost MessagesSuperhuman · OASuperhuman interview questions
  • Reverse a StringFlexTrade · OAFlexTrade interview questions
  • Missing WordsVanguard · OAVanguard interview questions

LinkedIn interview experiences

  • LinkedIn Senior MLE Interview Questions: 1 Experience
  • LinkedIn Staff AI Engineer Phone Screens: 1 Experience
  • LinkedIn Experienced MLE Onsite: 1 Experience
  • LinkedIn Coding with AI Interview: 4 Experiences
  • LinkedIn Experienced Infrastructure SWE Onsite: 1 Experience
All LinkedIn interview questionsSee LinkedIn hiring insights
Saved
class Solution {
    public int firstOccurrence(String s, String x) {
      // write your code here
    }

}
Checking account…