you are given an array A having N integers which represents the assembly line.Each integer represents the height of a student.
print the indexes of all the students who stand at wrong position in the line.
input; 9--------denotes N
11 8 4 26 7 9 2 16 1 ------denotes array A
output:0 1 3 4 6 8
Answers
Answered by
11
Answer:
for i in range(len(A)):
if A[i] > A[i+1]:
print(A[i])
Explanation:
We need to find out whether the height of student behind the current index is less than the height of the student at the current index (height of n > height of n+1, where n is the index)
First, we implement a loop to iterate through the array. Then we use a conditional to check whether the index ahead has a lesser value than the current one. If it is less, then print the current index.
Similar questions