FastPrepFastPrep
Problem Brief

Maximum Domino Removals

OA

Amazon Games has introduced an exciting new game that revolves around dominoes! 🎲 The game consists of n dominoes, each having a distinct size represented by an array tiles.

In this game, the "order" of the dominoes is defined as the length of the longest strictly increasing subsequence (LIS) formed by their sizes.

Additionally, there is another array removalOrder, which contains integers ranging from 0 to n-1. These integers indicate the positions of dominoes that can be removed one by one in the specified sequence.

Your objective is to determine the maximum number of removals that can be performed while ensuring that the order (LIS) of the remaining dominoes remains at least a given threshold minOrder.

Parameters -

  • int tiles[n] – an array of n integers representing the sizes of dominoes.
  • int removalOrder[n] – an array specifying the sequence in which the dominoes should be removed.
  • int minOrder – an integer representing the minimum required LIS that must be maintained after removals.
  • Return -

    The function should return a single integer, which represents the maximum number of removals possible while keeping the longest strictly increasing subsequence at least minOrder.

    1Example 1

    Input
    tiles = [1, 4, 4, 2, 5, 3], removalOrder = [2, 1, 4, 0, 5, 3], minOrder = 3
    Output
    3
    Explanation
    In this example, the player can remove dominoes in the order specified by remove. After each removal, the length of the LIS of the remaining dominoes should be at least min_order. The task is to find out the maximum number of such removals possible.
    public int maximumDominoRemovals(int[] tile, int[] removalOrder, int minOrder) {
      // write your code here
    }
    
    Input

    tiles

    [1, 4, 4, 2, 5, 3]

    removalOrder

    [2, 1, 4, 0, 5, 3]

    minOrder

    3

    Output

    3

    Sign in to submit your solution.