The placement session has begun in a college. There is N number of students standing outside an interview room in a line. It is given that the person who goes first has higher chances of selection.
Each student has a number associated with them representing their problem-solving capability. The higher the capability the higher the chances of selection. Now every student wants to know the number of students ahead of him with higher problem-solving capability.
Input: 6(number of students) {4 , 9 , 5 , 3 , 2 , 10}
Output: {0 , 0 , 1 , 3 , 4 , 0}
#include <stdio.h>
int main()
{
int n;
printf("\nEnter number of students: ");
scanf("%d",&n);
printf("\nEnter the capabilities of each student: ");
int capability[n];
for(int i=0;i<n;i++){
scanf("%d",&capability[i]);
}
printf("0 ");
for(int i=1;i<n;i++){
int count =0;
for(int j=1;j<i;j++){
if (capability[j] >= capability[i]){
count+=1;
}
}
printf("%d ",count);
}
return 0;
}
Comments
Leave a comment