I need a solution to this problem

Revision en3, by NewCoder100, 2025-10-13 14:49:11

Can someone please tell me an approach and possibly the optimal code for this problem.

Given an array A, you need to split the array into non empty subarrays such that each subarray is a permutation (each number from 1 to the n appears exactly once where n is the size of the subarray). For eg: A=2,1,3,6,3,1,2,5,4,2,1. Then the subarrays are {2,1,3},{6,3,1,2,5,4},{2,1}. You need to return these subarrays. It is guaranteed that answer always exists and the given array can always be split in such a way that every subarray is a permutation.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English NewCoder100 2025-10-13 14:49:11 144
en2 English NewCoder100 2025-10-13 11:45:27 2 Tiny change: 'nd possible the code ' -> 'nd possibly the code '
en1 English NewCoder100 2025-10-13 11:44:59 434 Initial revision (published)