Problem 59876. Out-of-Place Elements Count

Determine the number of elements in a list of integers that are not in their original order after sorting the list in ascending order.
For example, given the input vector [4, 2, 5, 1, 3], after sorting it becomes [1, 2, 3, 4, 5]. Comparing the sorted elements with the original elements:
  • 1 is at position 4, so it's not in its original position.
  • 2 is at position 2, so it's in its original position.
  • 3 is at position 5, so it's not in its original position.
  • 4 is at position 1, so it's not in its original position.
  • 5 is at position 3, so it's not in its original position.
Therefore, there are 4 elements (1, 3, 4 and 5) that are not in their original order. So, the function returns 4.

Solution Stats

64.29% Correct | 35.71% Incorrect
Last Solution submitted on May 05, 2024

Solution Comments

Show comments

Problem Recent Solvers8

Suggested Problems

More from this Author46

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!