Height Checker

EasyArraySortingCounting Sort

Solution

export function heightChecker(heights: number[]): number {
  const expected = [...heights].sort((a, b) => a - b);
  return heights.filter((height, i) => height !== expected[i]).length;
}