Entries from 2019-03-20 to 1 day

Triangle 100% Solution in Javascript

Question app.codility.com My Solution app.codility.com function solution(A) { if (A.length < 3) return 0; A.sort((a, b)=>(a - b)); for (let i = 2; i < A.length; i++) { if (A[i] < A[i-1] + A[i-2]) { return 1; } } return 0; }

MaxProductOfThree 100% Solution in Javascript

Question app.codility.com My Solution I (O(NlogN)) app.codility.com function solution(A) { A.sort((a, b)=>(a - b)); // 2 types (--+) or (+++) let type1 = A[0]*A[1]*A[A.length-1]; let type2 = A[A.length-1]*A[A.length-2]*A[A.length-3]; retur…

Distinct 100% Solution in Javascript

Question app.codility.com My Solution app.codility.com function solution(A) { if (A.length === 0 || A.length === 1) return A.length; A.sort((a, b)=>(a - b)); let cur = A[0]; let count = 1; for (let i = 0; i < A.length; i++) { if (A[i] != c…

CountDiv 100% Solution inJavascript

Question app.codility.com My Solution (O(1)) app.codility.com function solution(A, B, K) { // find the smallest multiple of K (A or above) let minKsMult = Math.ceil(A/K)*K; // there's none if (minKsMult > B) return 0; else return Math.floo…

MinAvgTwoSlice 100% Solution in Javascript

Question app.codility.com My Solution This is the most challenging one I've ever seen in codility (if you also start from Q1 to here), the trick is that any slices of arbitrary length can be broken into sub-slices of length 2 or 3. The pro…