Maximize Beauty
FULLTIME
The beauty of an array of length m is defined as the number of integers i (1 ≤ i ≤ m ) such that a[i] = i .
Given an array arr of n integers, the following operation can be performed on the array while its length is greater than 1:
Find the maximum possible beauty of the array after performing this operation any number of times.
Function Description
Complete the function maximizeBeauty in the editor below.
maximizeBeauty has the following parameter:
int arr[n] : the given array
Returns
int : the maximum possible beauty of the array
Example 1 :
Input: arr = [1, 3, 2, 5, 4, 5, 3]
Output: 4
Explanation:
One optimal sequence of operations is shown.
Return 4.
Note that there can be more than one final array with maximum beauty, like [1, 2, 5, 4, 5, 3] in this case.
Example 2 :
Input: arr = [6, 3, 2, 4, 3, 4]
Output: 3
Explanation:
One optimal sequence of operations is shown.
The maximum possible beauty of the array is 3.
Note that there can be more than one final arr with max beauty, like [1, 2, 5, 4, 5, 3] in this case.
Example 3 :
Input: arr = [1, 3, 2, 5, 4, 5, 3]
Output: 4
Explanation:
One optimal sequence of operations is shown.
Return 4.
Constraints:
Get one-to-one training from Google Facebook engineers
Top-notch Professionals
Learn from Facebook and Google senior engineers interviewed 100+ candidates.
Most recent interview questions and system design topics gathered from aonecode alumnus.
One-to-one online classes. Get feedbacks from real interviewers.
Customized Private Class
Already a coding expert? - Advance straight to hard interview topics of your interest.
New to the ground? - Develop basic coding skills with your own designated mentor.
Days before interview? - Focus on most important problems in target company question bank.