FastPrepMaximum Beauty by Deletions
Problems/Maximum Beauty by Deletions

Maximum Beauty by Deletions

Meesho logoMeesho● MediumINTERNNEW GRADOA

Updated Dec 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Meesho online assessment for intern and SDE1 roles. You delete elements from an array, keeping the order of the rest, so that as many elements as possible equal their own index. You return that count. The report gives the task and the limits, written from memory.

The report does not say whether indices start at 0 or 1. Here, they start at 1, which fits values that are at least 1. The report has no examples, so all three are ours.

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

Given an integer array a, delete some of its elements so that the remaining array has the largest possible beauty, and return that beauty.

The beauty of an array b of length m is the number of indices i with 1 <= i <= m and b[i] == i. Indices start at 1, so the first element is b[1].

You may repeat this operation any number of times, including zero: if the current array has length at least 2, choose any element and delete it. The other elements keep their order. So at least one element always remains.

Function

maxBeauty(a: int[]) → int

Examples

Example 1

a = [1,9,3]return = 2

Keep every element. Then b[1] = 1 and b[3] = 3, so the beauty is 2. The 9 never matches its index, but deleting it would move the 3 to index 2, and [1, 3] has beauty 1. No array can do better, because a beauty of 3 would need the values 1, 2 and 3. So the answer is 2.

Example 2

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

Kept as it is, only b[1] = 1 matches. Delete the 3 at index 2 to get [1, 2, 3], where every index matches. The answer is 3.

Example 3

a = [4,4,4]return = 0

Every value is 4, but any remaining array has at most 3 elements, so no index can hold a 4. Whatever you delete, the beauty is 0.

Constraints

  • 1 <= a.length <= 2000
  • 1 <= a[i] <= 10^5

More Meesho Online Assessment questions

  • Efficient DeploymentsOA · Seen Jun 2026
  • Distinct MovesOA · Seen Apr 2025

Similar questions at other companies

  • Maximum Score with Prime JumpsMicrosoft · OAMicrosoft interview questions
  • Card Game: Best First-Player ScoreShopify · OAShopify interview questions
  • Maximum Game Score with Fixed Forward JumpsStripe · OAStripe interview questions
  • 0/1 KnapsackConfluent · OAConfluent interview questions
  • Minimum Cost to Tile a Strip with Widths 1, 2, and 3Infosys · OAInfosys interview questions
  • Maximum Subarray SumStraive · OA
  • Longest Increasing Price SubsequenceOpenAI · OAOpenAI interview questions
  • Lowest-Cost Shirt Color ScheduleElevenLabs · OAElevenLabs interview questions
  • Maximum Game Board ScoreJP Morgan Chase · OAJP Morgan Chase interview questions
  • API Bandwidth AllocationArista Networks · OAArista Networks interview questions
See Meesho hiring insights
Saved
class Solution {
    public int maxBeauty(int[] a) {
      // Write your code here.
    }

}
Checking account…