Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
1 like 0 dislike
866 views
in Online Assessments by Expert (108,190 points) | 866 views

1 Answer

0 like 0 dislike
Tan is a school teacher. Her manager Taru asks her to bring the maximum number of students from his class where there are at max X pair of adjacent students whose heights is not the same. In similar words Tan has to find the maximum number of students standing in ascending order of their height such that there are only X adjacent pair of students whose height are not the same.

 

1<=n<=1000
1<=array element <=1000
1<=X<=1000

 

What could be the optimal solution?

 

e.g
arr[]={1,1,2,3}
X=1

 

ans=3
we can take 1,1,2 or 1,1,3
by Expert (108,190 points)

Get best answers to any doubt/query/question related to programming , jobs, gate, internships and tech-companies. Feel free to ask a question and you will receive the best advice/suggestion related to anything you ask about software-engineering , development and programming problems .