Guest User

Untitled

a guest
Jul 22nd, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. function solution(A) {
  2. // make a dictionary of expected values: O(n)
  3. let map = []
  4.  
  5. for (let i = 0; i < A.length + 1; i+= 1) {
  6. map[i] = { num: i+1, bool: -1 }
  7. }
  8.  
  9. // evaluate subset against dictionary, marking included values: O(n)
  10. for (let j = 0; j < A.length; j+= 1) {
  11. let num = A[j] // find the num in A
  12. map[num -1].bool = 0 // mark as found in map
  13. }
  14.  
  15. // evaluate dicionary for the missing values: O(n)
  16. for (let k = 0; k < map.length; k+= 1) {
  17. if(map[k].bool === - 1) {
  18. return map[k].num
  19. }
  20. }
  21. }
Add Comment
Please, Sign In to add comment