FastPrepLargest Consistent Visiting Group
Problems/Largest Consistent Visiting Group

Largest Consistent Visiting Group

AuxoAI logoAuxoAI● HardFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This was one of four coding questions in an AuxoAI online assessment for an AI Engineer role. Each day lists the order in which k friends visited, and you want the largest set of friends whose relative order never changes across the days.

The post calls this set a window, but its own example picks friends 1 and 3, who are not next to each other on the first day. So here a group can skip friends: it is the longest order shared by all days. The post gives no limits. Here, there are up to 5 days and up to 1,000 friends, and you return only the size.

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

There are k friends, numbered from 1 to k. For n days, you write down the order in which the friends visited you. You get these orders as a 2D array orders with n rows: orders[d] lists all k friends in the order they visited on day d.

Pick a group of friends. The group is consistent when every two friends in it keep the same order on every day: if friend a visits before friend b on one day, then a visits before b on all n days.

The friends in a group do not need to visit one right after another. Other friends may visit between them.

Return the size of the largest consistent group. A group of one friend is always consistent.

Function

largestConsistentGroup(orders: int[][]) → int

Examples

Example 1

orders = [[1,2,3],[2,1,3]]return = 2

Friends 1 and 2 swap places between the two days, so they cannot be in the same group. Friend 3 visits after both of them on both days.

So {1, 3} and {2, 3} are consistent groups of size 2, and no group of size 3 works.

Example 2

orders = [[1,4,2,3],[4,1,2,3],[1,2,4,3]]return = 3

The group {1, 2, 3} visits in the order 1, 2, 3 on all three days, even though friend 4 sometimes comes between them.

Friend 4 cannot join it: 4 is after 1 on day 0 but before 1 on day 1. So the answer is 3.

Example 3

orders = [[1,2,3],[3,2,1]]return = 1

The second day reverses the first, so every two friends switch order. Only groups of one friend are consistent.

Constraints

  • 1 <= n == orders.length <= 5
  • 1 <= k == orders[d].length <= 1000
  • 1 <= orders[d][p] <= k
  • Each row orders[d] contains every number from 1 to k exactly once.

More AuxoAI Online Assessment questions

  • Count Valid Square PairsOA · Seen Nov 2026
  • Sliding Window MedianOA · Seen Nov 2026
  • Split Array Largest SumOA · Seen Nov 2026

Similar questions at other companies

  • Select Transactions with Child-Pays-for-Parent PackagesCoinbase · PHONE SCREENCoinbase interview questions
  • Parallel Courses IIIGoogle · ONSITE INTERVIEWGoogle interview questions
  • Cheapest Flights Within K StopsGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Planets Queries from Planet OneAdyen · PHONE SCREENAdyen interview questions
  • Minimum Leaf Path Sum over All RootsInfosys · OAInfosys interview questions
  • Delete K Subsets for Maximum ScoreRubrik · OARubrik interview questions
  • Optimize Discount Selection Under a Point BudgetPalantir · OAPalantir interview questions
  • Maximum Index-Weighted Sum with Disjoint SwapsVisa · OAVisa interview questions
  • Recoverable Elements from Range-Sum MeasurementsEthos Life · OA
  • Maximum Sum of HeightsVirtu Financial · OAVirtu Financial interview questions
See AuxoAI hiring insights
Saved
class Solution {
    public int largestConsistentGroup(int[][] orders) {
        // Write your code here.
    }
}
Checking account…