{"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