A pretty trivial recursive solution has been implemented.
The solution is not effective though. The complexity is O(2n(n-1)) in worst case, and it leads to extremely huge execution time on huge input arrays.
Also, the recursion introduces additional constraints disallowing to handle huge input arrays because of the StackOverflowError.
However it still passed all the HackerRank tests and was accepted.
O(2n(n-1))
in worst case, and it leads to extremely huge execution time on huge input arrays. Also, the recursion introduces additional constraints disallowing to handle huge input arrays because of theStackOverflowError
. However it still passed all the HackerRank tests and was accepted.