0 day streak
Anonymous · shared experience20 Jun 2026 · 8 views

Databricks: Earliest substring that is a permutation of a shorter pattern

Interview question #Databricks Phone screen

Problem. You get a long text and a shorter pattern. Find the earliest contiguous substring of the text that uses exactly the same characters as the pattern, with the same counts, in any order. Return its starting position, or -1 if no such window exists. The candidate gave this wording as approximate.

Approach that worked. A fixed-size sliding window, as long as the pattern, that keeps character counts up to date as it moves. The candidate said it went smoothly.

Follow-ups.

  • How would you handle the character set if the input could be UTF-8 or Unicode rather than plain ASCII?
  • The candidate was expected to write their own test cases.

What the interviewer cared about. Working through edge cases without prompting, such as an empty pattern or a pattern longer than the text. The interviewer also wanted to see how error conditions and the not-found result were reported. The interviewer spoke quickly, so it helps to confirm the requirements out loud before coding.

0 comments

Comments 0

No comments yet. Ask the author something, or add what happened in your own round.