FastPrepShortest Sequence of Source Subsequences
Problems/Shortest Sequence of Source Subsequences

Shortest Sequence of Source Subsequences

Pinterest logoPinterest● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names onsite coding 1 as analogous to LeetCode 1055. This is that recognizable shortest-way subsequence contract and matches the source at about 92%.

Form target by concatenating subsequences of source. Return the minimum number of source subsequences required, or -1 when impossible. An empty target requires zero subsequences.

Function

shortestSourceSubsequences(source: String, target: String) → int

Examples

Example 1

source = "abc"target = "abcbc"return = 2

Use abc followed by bc.

Example 2

source = "abc"target = "acdbc"return = -1

The character d never occurs in source.

Example 3

source = "xyz"target = ""return = 0

No subsequence is needed.

Constraints

  • 1 <= source.length <= 10^5.
  • 0 <= target.length <= 10^5.
  • Both strings contain lowercase English letters.

More Pinterest problems

  • Gaussian Naive Bayes Classifier (Machine Learning OA)OA · Seen Nov 2026
  • Top K Pins with Insert and QueryPHONE SCREEN · Seen Nov 2026
  • Pins Violation Log QueriesPHONE SCREEN · Seen Nov 2026
All Pinterest interview questionsSee Pinterest hiring insights
Saved
class Solution {
    public int shortestSourceSubsequences(String source, String target) {
        // Write your solution here.
    }
}
Checking account…