Find the Substring
Updated
Problem statement
Given s and x, determine the zero-based index of the first occurrence of x in s.
- String
sconsists of lowercase letters in the range ascii[a-z]. -
String
xconsists 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
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