In this blog post, I will be giving a brief description about another important pattern for technical interviews. This pattern is called Cyclic Sort.
This pattern is very useful for solving problems that involves arrays containing numbers in a given range or finding duplicates or missing numbers. In this pattern, we iterate over the given array one number at a time. If the current number that we are iterating is not at the correct index then we swap it with the number at its correct index.
Identification of this pattern:
This pattern can be identified by following ways;
- If the problem involves with a sorted array in a given range,
- If the problem involves finding the missing or duplicate number in a sorted or rotated array.