FastPrepCase-Insensitive Target Distances
Problems/Case-Insensitive Target Distances

Case-Insensitive Target Distances

Google logoGoogle● MediumNEW GRADPHONE SCREEN

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The Google ML new-grad report describes a similar interview question and gives the Google/g distance example. Case-insensitive matching follows that example; absent-target behavior and letter bounds are specified for this exercise. Approximate source match: 90%.

For every character position in s, return the smallest absolute index distance to any occurrence of target. Match uppercase and lowercase ASCII letters as the same letter. A target position has distance zero.

If the target does not occur, return -1 for every position. An empty string returns an empty array.

Function

shortestDistanceToTarget(s: String, target: String) → int[]

Examples

Example 1

s = "Google"target = "g"return = [0,1,1,0,1,2]

The uppercase G and lowercase g are both target occurrences, at indices 0 and 3.

Example 2

s = "abAba"target = "a"return = [0,1,0,1,0]

Indices 0, 2 and 4 match, so each intervening character is one step away.

Example 3

s = "xyz"target = "a"return = [-1,-1,-1]

No position contains the target letter.

Constraints

  • 0 <= s.length <= 100000.
  • s contains only ASCII letters.
  • target contains exactly one ASCII letter.

More Google Phone Screen questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
  • Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEWDuolingo interview questions
  • Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Largest Number Below N from Reusable DigitsByteDance · PHONE SCREENByteDance interview questions
  • Merge Weekday and Time IntervalsNextdoor · PHONE SCREENNextdoor interview questions
  • Query Words Within K PositionsPalantir · PHONE SCREENPalantir interview questions
  • Group AnagramsWorkday · PHONE SCREEN
  • Apply Operations to Make a String EmptyFlexport · PHONE SCREENFlexport interview questions
  • Elevator Scheduling SimulationOpenAI · PHONE SCREENOpenAI interview questions
  • Word BreakAmazon · PHONE SCREEN · ONSITE INTERVIEW

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[] shortestDistanceToTarget(String s, String target) {
        // Write your code here
    }
}
Checking account…