Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. A non-empty zero-indexed array A consisting of N integers is given.
  2.  
  3. A permutation is a sequence containing each element from 1 to N once, and only once.
  4.  
  5. For example, array A such that:
  6.  
  7. A[0] = 4
  8. A[1] = 1
  9. A[2] = 3
  10. A[3] = 2
  11. is a permutation, but array A such that:
  12.  
  13. A[0] = 4
  14. A[1] = 1
  15. A[2] = 3
  16. is not a permutation, because value 2 is missing.
  17.  
  18. The goal is to check whether array A is a permutation.
  19.  
  20. Write a function:
  21.  
  22. ```
  23. def solution(A)
  24. ```
  25.  
  26. that, given a zero-indexed array A, returns 1 if array A is a permutation and 0 if it is not.
  27.  
  28. For example, given array A such that:
  29.  
  30. A[0] = 4
  31. A[1] = 1
  32. A[2] = 3
  33. A[3] = 2
  34. the function should return 1.
  35.  
  36. Given array A such that:
  37.  
  38. A[0] = 4
  39. A[1] = 1
  40. A[2] = 3
  41. the function should return 0.
  42.  
  43. Assume that:
  44.  
  45. + N is an integer within the range [1..100,000];
  46. + each element of array A is an integer within the range [1..1,000,000,000].
  47. Complexity:
  48.  
  49. + expected worst-case time complexity is O(N);
  50. + expected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments).
  51.  
  52. Elements of input arrays can be modified.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement