Height Checker Lab

Easy
1
2
38.9% Acceptance

In this lab, you will be implementing a function to find the mismatched heights in a line of students. To be more specific, you need to create a function heightChecker(heights) that takes an array of integers representing the heights of students and returns the number of indices where heights[i] is not equal to the expected heights[i] in a non-decreasing order.

The lab description provides you with initial examples and constraints for input array heights.

Before starting, please note the following important details:

  1. Use ESM import/export everywhere.
  2. If you use any function or variable inside the evaluation script, make sure to export it within your code.

Let's walk through a couple more examples to further clarify the problem statement:

Example 4:

heightChecker([4, 3, 2, 1]);

Output: 2

Explanation: The current order of heights is [4, 3, 2, 1]. The expected non-decreasing order would be [1, 2, 3, 4]. The indices that do not match are 0 and 3.

Example 5:

heightChecker([1, 1, 1, 2, 3, 4]);

Output: 0

Explanation: The current order of heights is [1, 1, 1, 2, 3, 4]. The expected non-decreasing order would also be [1, 1, 1, 2, 3, 4]. All indices match.

Now, you have to create challenges for this lab. Remember the final length of the array testlog should be the same as the number of challenges, and the order of evaluation script try-catch blocks must match the order of challenges written.

Once you have completed the lab, verify all the code pieces, descriptions, and challenges. Good luck!