FastPrepLongest Common Contiguous Subarray
Problems/Longest Common Contiguous Subarray

Longest Common Contiguous Subarray

Coinbase logoCoinbase● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Coinbase phone screen. Our version is about 75% the same as the reported array task. We kept its goal, the longest common subarray. The report gives no samples and no detail on what to return. We chose integer inputs, returning the actual run, the earliest occurrence on ties, the empty case, and the limits. We wrote all of the complete examples.

Given arr1 and arr2, return the longest sequence of consecutive values that appears in both arrays. The values must appear in the same order, without skipping any elements.

For this exercise, assume the inputs contain integers and return the selected values, rather than only the length. If several longest occurrences exist, choose the smallest starting index in arr1, then the smallest starting index in arr2.

For this exercise, assume an empty array is returned when no nonempty common subarray exists, including when either input is empty. Preserve signed values and repeated elements.

Function

longestCommonSubarray(arr1: int[], arr2: int[]) → int[]

Examples

Example 1

arr1 = [1,2,3,2,1]arr2 = [3,2,1,4,7]return = [3,2,1]

This example returns the three-element contiguous run, rather than a subsequence or only its length.

Example 2

arr1 = [4,5,9,1,2]arr2 = [1,2,8,4,5]return = [4,5]

This tie chooses [4,5], whose occurrence starts earlier in the first array.

Example 3

arr1 = [-1,0,-1,2]arr2 = [8,-1,0,-1,3]return = [-1,0,-1]

This example preserves negative values, zero and repeated values in the returned run.

Constraints

  • For this exercise, assume 0 <= arr1.length, arr2.length <= 500.
  • For this exercise, assume every element is an integer from -1000 through 1000.

More Coinbase interview questions

  • Select Transactions with Child-Pays-for-Parent PackagesPHONE SCREEN · Seen Oct 2026
  • Lexicographically Smallest Topological OrderPHONE SCREEN · Seen Apr 2022
  • Ordered Badge Entry and Exit ViolationsPHONE SCREEN · Seen Feb 2022
  • Justify Text to a Fixed WidthPHONE SCREEN · Seen Jun 2021
  • Scheduled Payments with Account AliasesONSITE INTERVIEW · Seen Oct 2026
  • Task Management SystemOA · Seen Sep 2026
  • Cloud Compute Credits SystemOA · Seen Aug 2026
  • Dynamic Fixed-K Score LeaderboardONSITE INTERVIEW · Seen Aug 2026
  • Minimum Days for Fixed-Order Tasks with CooldownONSITE INTERVIEW · Seen Aug 2026
  • Sliding-Window Averages as Reduced FractionsONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • Maximum Subarray Sum with One DeletionServiceNow · PHONE SCREENServiceNow interview questions
  • Maximum Product of a Contiguous SubarrayLinkedIn · PHONE SCREENLinkedIn interview questions
  • Fewest Coins CombinationBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Longest Increasing SubsequenceByteDance · PHONE SCREENByteDance interview questions
  • Jump GamePaytm · PHONE SCREENPaytm interview questions
  • Query Words Within K PositionsPalantir · PHONE SCREENPalantir interview questions
  • House RobberVisa · PHONE SCREENVisa interview questions
  • Best Improvement Period of at Least K IntervalsAmazon · PHONE SCREEN
  • Longest Increasing SubsequenceAngel One · PHONE SCREEN
  • Match Shops and BuyersGoogle · PHONE SCREENGoogle interview questions

Coinbase interview experiences

  • Coinbase SWE Phone Screen and Final Loop: 1 Experience
All Coinbase interview questionsSee Coinbase hiring insights
Saved
class Solution {
    public int[] longestCommonSubarray(int[] arr1, int[] arr2) {
        // Write your code here.
        return new int[0];
    }
}
Checking account…