FastPrepMaximum Good Triplet Distance
Problems/Maximum Good Triplet Distance

Maximum Good Triplet Distance

Google logoGoogle● HardINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The statement leaves one endpoint name undefined and does not give input limits or the result when nothing qualifies. Our version, based on symmetric visibility, is about 94% the same as the reported question.

You are given an integer array A. A triplet of indices (i, j, k) is good when i < j < k and both visibility conditions hold:

  • For every index p with i < p < j, A[p] < A[i] and A[p] < A[j].
  • For every index q with j < q < k, A[q] < A[j] and A[q] < A[k].

Return the maximum possible index distance k - i among all good triplets. Return -1 if no good triplet exists.

Function

maximumGoodTripletDistance(A: int[]) → int

Examples

Example 1

A = [5,1,4,2,6]return = 4

The triplet (0, 2, 4) is good. Value 1 is strictly below both 5 and 4, while value 2 is strictly below both 4 and 6. Its distance is 4 - 0 = 4.

Example 2

A = [3,3,1,3,3]return = 3

Equal-height endpoints block visibility through one another because every interior value must be strictly smaller. One maximum-span good triplet is (0, 1, 3), with distance 3.

Constraints

  • 3 <= A.length <= 200000
  • -10^9 <= A[i] <= 10^9

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

  • Maximize Shipment Order by Sorting One WindowAmazon · OA
  • Most Segments That Sort the ArrayRippling · OARippling interview questions
  • Maximum Sum of HeightsVirtu Financial · OAVirtu Financial interview questions
  • Alternating Jumps to the Last IndexExpedia · OAExpedia interview questions
  • Pipe Removal TurnsWells Fargo · OAWells Fargo interview questions
  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Sum of Subarray MinimumsNVIDIA · OANVIDIA interview questions
  • Shopkeeper Final Price SummaryMicrosoft · OAMicrosoft interview questions
  • Nested Recipe Blocks (Game Adaptation)Roblox · OARoblox interview questions
  • Maximum Capped Histogram Area After One RemovalMyntra · OAMyntra interview questions

Interview reports that mention this question

  • Google OA: What It Tests (2026)

Google interview experiences

  • Google L5 Security Engineer Domain Knowledge Round: 1 Experience
  • Google Software Engineer Onsite Questions: 10 Experiences
  • 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 maximumGoodTripletDistance(int[] A) {
        // write your code here
    }
}
Checking account…