FastPrepIs Substring
Problems/Is Substring

Is Substring

Zillow logoZillow● EasyFULLTIMEONSITE INTERVIEW

Updated Dec 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported at Zillow by a candidate for a software engineering position in San Francisco, California, in a report dated November 10, 2017; the candidate rated the experience positive and got an offer. The first step was a phone screen with general questions about the candidate's earlier work and the parts of software engineering that interest them. The second was a batch day for students who came in by plane: a morning with two technical interviews, one right after the other, then a presentation on engineering and a team project.

The report's question asks for a method that tells whether the second of two strings appears inside the first. The report does not say which interview asked it. Because the phone screen was about past work and the technical interviews were on the batch day, we list it as an onsite interview; this is our inference.

The report does not say how the strings reach the code, which characters they hold, or how long they can be. Our choices: the function isSubstring gets haystack (the first string) and needle (the second string) and returns true when needle occurs in haystack as a run of consecutive characters, and false otherwise; both strings hold lowercase English letters, with lengths from 1 to 10,000. The rule against calling a built-in substring search is ours as well.

Our version is about 90% the same as the reported question.

You are given a string haystack and a string needle. Return true if needle appears inside haystack as a block of consecutive characters, and false otherwise.

Put another way, the answer is true when some index i exists such that the needle.length characters of haystack that begin at index i spell out needle exactly.

Write the character comparisons yourself: do not call a built-in substring search such as indexOf, contains, find, strings.Contains or Python's in operator on strings.

Function

isSubstring(haystack: String, needle: String) → boolean

Examples

Example 1

haystack = "abacabab"needle = "abab"return = true

Indexes start at 0. The four characters of haystack starting at index 4 are "abab", which equals needle, so the answer is true. The block starting at index 0 is "abac", which differs from needle in its last character.

Example 2

haystack = "listing"needle = "lists"return = false

A block of five characters can start at index 0, 1 or 2, giving "listi", "istin" and "sting". None of them equals needle, so the answer is false.

Example 3

haystack = "home"needle = "homeowner"return = false

needle has 9 characters and haystack has 4, so needle cannot fit inside haystack and the answer is false.

Constraints

  • 1 <= haystack.length <= 104
  • 1 <= needle.length <= 104
  • haystack and needle consist of lowercase English letters.

More Zillow Onsite Interview questions

  • Valid ParenthesesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
  • Build a Hash TablePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2023
  • Spiral MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2022
  • First Subarray with the Largest SumOA · ONSITE INTERVIEW · Seen Aug 2021
  • Count Duplicate CharactersONSITE INTERVIEW · Seen Oct 2020
  • Symmetric TreeONSITE INTERVIEW · Seen Oct 2020
  • Decision Tree Classifier from ScratchONSITE INTERVIEW · Seen Nov 2019
  • Uniform to Normal NumbersONSITE INTERVIEW · Seen Nov 2019
  • Check Each Word in a Character GridONSITE INTERVIEW · Seen Oct 2018
  • Find Median from Data StreamPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2018

Similar questions at other companies

  • String CompressionShnoor International · ONSITE INTERVIEW
  • Longest Spoken PrefixElevenLabs · ONSITE INTERVIEWElevenLabs interview questions
  • Palindrome Check Ignoring SymbolsWalmart · ONSITE INTERVIEWWalmart interview questions
  • Reverse a String Keeping Dashes in PlaceNykaa · ONSITE INTERVIEWNykaa interview questions
  • Reverse Vowels of a StringGoogle · ONSITE INTERVIEWGoogle interview questions
  • Valid Palindrome After NormalizationKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Count Binary SubstringsDocuSign · ONSITE INTERVIEWDocuSign interview questions
  • Minimum Changes for Palindromic BlocksCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
  • Palindrome Match PercentageApple · ONSITE INTERVIEWApple interview questions
  • Reverse A StringNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
All Zillow interview questionsSee Zillow hiring insights
Saved
class Solution {
    public boolean isSubstring(String haystack, String needle) {
        // Write your code here.
    }
}
Checking account…