{"id":343,"date":"2020-02-24T08:31:00","date_gmt":"2020-02-24T08:31:00","guid":{"rendered":"https:\/\/danwritescode.com\/?p=343"},"modified":"2020-06-23T08:48:15","modified_gmt":"2020-06-23T08:48:15","slug":"permmissingelem-100-correct-javascript-codility-solution","status":"publish","type":"post","link":"https:\/\/danwritescode.com\/permmissingelem-100-correct-javascript-codility-solution\/","title":{"rendered":"PermMissingElem 100% Correct Javascript Codility Solution"},"content":{"rendered":"\n

This is another simple practice run with a O(n) \/ O(N * log(N)) solution. Just iterate through the array once and fill an empty array of length N+1 with 1s for each element you find. At the end display the element from 0.<\/p>\n\n\n\n

function solution(A) {\n  let N = A.length;\n  let count = new Array(N+1).fill(0);\n  for (let i = 0; i< N; i++) {\n      count[A[i]-1] = 1;\n  }\n  \/\/add 1 because the array starts at 1\n  return(count.indexOf(0)+1)\n}<\/code><\/pre>\n\n\n\n

See it in action here: https:\/\/app.codility.com\/demo\/results\/trainingM9UEJP-YPR\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"

This is another simple practice run with a O(n) \/ O(N * log(N)) solution. Just iterate through the array once and fill an empty array of length N+1 with 1s for each element you find. At the end display the element from 0. See it in action here: https:\/\/app.codility.com\/demo\/results\/trainingM9UEJP-YPR\/<\/p>\n","protected":false},"author":1,"featured_media":344,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,5,12],"tags":[],"_links":{"self":[{"href":"https:\/\/danwritescode.com\/wp-json\/wp\/v2\/posts\/343"}],"collection":[{"href":"https:\/\/danwritescode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/danwritescode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/danwritescode.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/danwritescode.com\/wp-json\/wp\/v2\/comments?post=343"}],"version-history":[{"count":0,"href":"https:\/\/danwritescode.com\/wp-json\/wp\/v2\/posts\/343\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/danwritescode.com\/wp-json\/wp\/v2\/media\/344"}],"wp:attachment":[{"href":"https:\/\/danwritescode.com\/wp-json\/wp\/v2\/media?parent=343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/danwritescode.com\/wp-json\/wp\/v2\/categories?post=343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/danwritescode.com\/wp-json\/wp\/v2\/tags?post=343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}