Permcheck
Test description
Solution #1:
I thought getting the sum of all elements and comparing it with n ( n + 1) / 2 would do, but there are some cases where this returns true but the array is still not a permutation! shooooot. thank God that I did not get 0% but 70%. Depending on the test case, I could even get something like 10%.
I thought getting the sum of all elements and comparing it with n ( n + 1) / 2 would do, but there are some cases where this returns true but the array is still not a permutation! shooooot. thank God that I did not get 0% but 70%. Depending on the test case, I could even get something like 10%.
Solution #2:
So I tried again. This time, I would just get the difference of two adjacent elements in the array, and if it's 2, then it means the element in between is missing. 100% for this. But is there anything not fully satisfiable?
So I tried again. This time, I would just get the difference of two adjacent elements in the array, and if it's 2, then it means the element in between is missing. 100% for this. But is there anything not fully satisfiable?
Solution #3:
Turns out I got 100% for both correctness and performance. However, I was still stuck inside my stereotype or whatever you call it-the limited perspective-I was only thinking the adjacent elements inside the array could be only different at most by 2 for some reason. It could be bigger than two, of course, for example: [1, 2, 6, 7]. Simple. Alternatively, I could only count the cases where A[i+1] - A[i] == 1 and leave out the A[i+1] - A[i] == 2 part because this does not mean anything.
Turns out I got 100% for both correctness and performance. However, I was still stuck inside my stereotype or whatever you call it-the limited perspective-I was only thinking the adjacent elements inside the array could be only different at most by 2 for some reason. It could be bigger than two, of course, for example: [1, 2, 6, 7]. Simple. Alternatively, I could only count the cases where A[i+1] - A[i] == 1 and leave out the A[i+1] - A[i] == 2 part because this does not mean anything.