← Goldman Sachs questions

Check if one string is a substring of another

Filed under Goldman Sachs · Also reported at CouponDunia

Free read 1 of 3

Use language-specific methods like 's2 in s1' or 's1.find(s2)'.

The question

Determine if string 's2' is a substring of string 's1'.

Constraints

  • Strings consist of standard characters
  • Empty substring is always contained
  • Case sensitivity is assumed

Examples

Input
s1='hello', s2='ell'
Output
true
Why
'ell' is found starting at index 1 of 'hello'.

Approach

  1. Use language-specific methods like 's2 in s1' or 's1.find(s2)'.

Solution

O(N*M) worst case, O(N) average

Python
def is_substring(s1, s2):
    return s2 in s1

Tips

  • What they are testing: Test with s2 longer than s1, empty s2, and s2 not present.
  • Common mistake: Off-by-one errors in the loop bounds when checking substrings.

Related Goldman Sachs questions

Collected from public candidate posts and coding forums. Updated Nov 2026.