{"id":374,"date":"2020-03-14T08:41:00","date_gmt":"2020-03-14T08:41:00","guid":{"rendered":"https:\/\/danwritescode.com\/?p=374"},"modified":"2020-06-25T08:47:32","modified_gmt":"2020-06-25T08:47:32","slug":"count-div-codility-100-correct-javascript-solution","status":"publish","type":"post","link":"https:\/\/danwritescode.com\/count-div-codility-100-correct-javascript-solution\/","title":{"rendered":"Count Div Codility 100% Correct Javascript Solution"},"content":{"rendered":"\n

The Count Div problems is classified as a medium difficulty but I found the solution to be quite trivial and easily solvable in O(1).<\/p>\n\n\n\n

The only thing we need to do is to calculate how many numbers are divisible by a third one in between two value.<\/p>\n\n\n\n

Thus, the solution:<\/p>\n\n\n\n

function solution(A, B, K) {\n    \/\/ write your code in JavaScript (Node.js 8.9.4)\n    \n    if (A === B) {\n        if (A % K === 0) {\n            return 1\n        }\n        else {\n            return 0\n        }\n    }\n    \n    leftLimit = Math.ceil(A\/K)\n    rightLimit = Math.floor(B\/K)\n    \n    return (rightLimit - leftLimit + 1)\n}<\/code><\/pre>\n\n\n\n

The report is here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"

The Count Div problems is classified as a medium difficulty but I found the solution to be quite trivial and easily solvable in O(1). The only thing we need to do is to calculate how many numbers are divisible by a third one in between two value. Thus, the solution: The report is here.<\/p>\n","protected":false},"author":1,"featured_media":375,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,5,6],"tags":[],"_links":{"self":[{"href":"https:\/\/danwritescode.com\/wp-json\/wp\/v2\/posts\/374"}],"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=374"}],"version-history":[{"count":0,"href":"https:\/\/danwritescode.com\/wp-json\/wp\/v2\/posts\/374\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/danwritescode.com\/wp-json\/wp\/v2\/media\/375"}],"wp:attachment":[{"href":"https:\/\/danwritescode.com\/wp-json\/wp\/v2\/media?parent=374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/danwritescode.com\/wp-json\/wp\/v2\/categories?post=374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/danwritescode.com\/wp-json\/wp\/v2\/tags?post=374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}