We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Absolute Permutation
Absolute Permutation
Sort by
recency
|
535 Discussions
|
Please Login in order to post a comment
Hi everybody, With n =10 and k = 1, i obtain 2 3 4 5 6 7 8 9 10 9 but the expected output is 2 1 4 3 6 5 8 7 10 9
Does somebody could explain why my output is not considered as a good answer ?
Thanks
A simple python solution that passes all the test cases consists of doing +k -k operations then give privilege to - k operation if applicable else + k operation if applicable to get the smallest P. If - k and + k can not be possible return -1. NOTE that using a set to test if the element has been already used is mandatory, otherwise test cases from 9 to 12 will exceed allowed time:
Easy python
Simple approach in python: