36.0k views
0 votes
c++ You are given an array A representing heights of students. All the students are asked to stand in rows. The students arrive by one, sequentially (as their heights appear in A). For the i-th student, if there is a row in which all the students are taller than A[i], the student will stand in one of such rows. If there is no such row, the student will create a new row. Your task is to find the minimum number of rows created.

User Volpav
by
5.1k points

1 Answer

3 votes

The below code will help you to solve the given problem and you can execute and cross verify with sample input and output.

#include<stdio.h>

#include<string.h>

int* uniqueValue(int input1,int input2[])

{

int left, current;

static int arr[4] = {0};

int i = 0;

for(i=0;i<input1;i++)

{

current = input2[i];

left = 0;

if(current > 0)

left = arr[(current-1)];

if(left == 0 && arr[current] == 0)

{

arr[current] = input1-current;

}

else

{

for(int j=(i+1);j<input1;j++)

{

if(arr[j] == 0)

{

left = arr[(j-1)];

arr[j] = left - 1;

}

}

}

}

return arr;

}

User Almalki
by
4.9k points