FastPrepMinimum Operations to Make a Subsequence
Problems/Minimum Operations to Make a Subsequence

Minimum Operations to Make a Subsequence

Google logoGoogle● HardFULLTIMEOA

Updated Nov 2026

QuestionExamples

Problem statement

Source note: Reported in a Google software engineer online assessment. You get two arrays, the first with distinct numbers. You must find the fewest numbers to add to the second array, anywhere you like, so that the first array shows up inside it in order.

The report was a photo of an online test question. The task was clear, but the input layout was cut off, and no limits or examples were shown. The limits and examples here are our own: each array holds up to 10^5 values from 1 to 10^9. The test read several cases from the input. Here, your function gets one case per call.

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

Given an integer array target whose values are all distinct and an integer array arr that may contain repeated values, return the minimum number of operations needed to make target a subsequence of arr.

In one operation, you insert one integer of your choice into arr at any position: at the start, at the end, or between two elements.

The problem statement continues
Pro

Examples

Example 1

target = [4,7,2]arr = [7,5,2,7]return = 1

The values 7 and 2 already appear in this order in arr. Insert 4 at the start to get [4,7,5,2,7], which contains [4,7,2] as a subsequence.

02 · Example 2
FastPrep Pro
Reported in 1 Google interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week

More Google Online Assessment questions

  • Book Reading EveningsOA · Seen Nov 2026
  • Count Score CategoriesOA · Seen Nov 2026
  • Minimum Cars for Rental RequestsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Shortest Path in a Binary MatrixOA · Seen Nov 2026
  • Robot Assembly Line ConflictsOA · Seen Oct 2026
  • Assign LockerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Biggest Number From DigitsOA · Seen Oct 2026
  • Consolidate On-Call RotationsOA · PHONE SCREEN · Seen Oct 2026
  • Decreasing SubsequencesOA · Seen Sep 2026
  • Minimize Absolute Difference of Server LoadsOA · Seen Sep 2026

Similar questions at other companies

  • Split Array to Minimize the Largest SumInfosys · OAInfosys interview questions
  • Split Array Largest SumAuxoAI · OA
  • Data ReorganizationGoldman Sachs · OAGoldman Sachs interview questions
  • Find Optimal LevelAmazon · OA
  • Array Reduction AlgorithmSnowflake · OASnowflake interview questions
  • Count Pairs of Overlapping SquaresCapital One · OACapital One interview questions
  • Bank Accounts with Balance HistoryMeta · OAMeta interview questions
  • Capacity to Ship Packages Within DaysMicrosoft · OA · ONSITE INTERVIEWMicrosoft interview questions
  • Minimum Distinct Prefix CostChubb · OAChubb interview questions
  • Rock JumpingIMC Trading · OAIMC Trading interview questions

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
CodePython 3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import heapq
from collections import defaultdict
 
class Solution:
def solve(self, values, queries):
# Build the adjacency structure
n = len(values)
graph = defaultdict(list)
for u, v in queries:
graph[u].append(v)
 
best = [float("inf")] * n
heap = [(0, 0)]
while heap:
cost, node = heapq.heappop(heap)
if cost > best[node]:
continue
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Google interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week