The season of vivas are ON!! There are a number of students in a class. Each of the students has to giveviva, but there is one rule teacher have decided to choose the students whose turn it will be to give vivaE The teacher is picking certain role numbers from the list of students. On each day, students with higherrole numbers than his left student's role number will be picked to give viva on that day. Determine thenumber of days after which no student from the initial picking is remaining to give viva, i.e. the time afterwhich there is no student with higher roll number on to his left.
Answers
Answered by
0
Answer:
import java.util.ArrayList;
import java.util.Scanner;
public class StudentViva {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ArrayList<Integer> al = new ArrayList<>();
for(int i=0; i<n; i++) {
al.add(sc.nextInt());
}
int c = 0;
while(true) {
boolean flag = true;
for(int i=1; i<al.size()-1; i++) {
if(al.get(i) > al.get(i-1) ) {
al.remove(i);
flag = false;
}
}
if(flag) {
break;
}else {
c++;
}
}
System.out.println(c);
}
}
Similar questions