The following tutorial is for macOS brew update && brew install imagemagick to your folder for the candidate images for stickers convert all jpg & jpeg to png magick mogrify -format png *.jpg magick mogrify -format png *.jpeg for all the p…
Question Solution function solution(A) { let peaks = new Array(A.length).fill(false); let peakCount = 0; for (let i = 1; i < A.length-1; i++) { if (A[i-1] < A[i] && A[i] > A[i+1]) { peaks[i] = true; peakCount++; } } if (peakCount === 0 || …
Question Solution function solution(A) { let prefixSumPeaks = new Array(A.length+1).fill(0); let peakArray = new Array(A.length).fill(0); let peakCount = 0; for (let i = 1; i < A.length-1; i++) { if (A[i-1] < A[i] && A[i] > A[i+1]) { peakA…
Question Solution function solution(N) { let min = Number.MAX_SAFE_INTEGER; for (let i = 1; i*i <= N; i++) { if (N%i === 0) { min = Math.min(min, i + N/i); } } return 2*min; }
Question Solution function solution(N) { let count = 0; let i = 1; while (i*i < N) { if (N % i === 0) { count += 2; // console.log(i); } i += 1; } if (i*i === N) { count += 1; } return count; }
Question app.codility.com My Solution app.codility.com def solution(A): fromStartMaxEnding = [0] * len(A) for i in range(1, len(A)-1): fromStartMaxEnding[i] = max(0, fromStartMaxEnding[i-1]+A[i]) fromEndMaxEnding = [0] * len(A) for i in ra…
Question app.codility.com My Solution app.codility.com def solution(A): allNegative = 1 maxNegative = -1 * 2**31 for i in range(len(A)): if A[i] > 0: allNegative = 0 break elif A[i] > maxNegative: maxNegative = A[i] if allNegative == 1: re…
Question app.codility.com My Solution app.codility.com def solution(A): # calculate the difference everyday diff = [0] * len(A) for i in range(1, len(A)): diff[i] = A[i]-A[i-1] # print(diff) # find the max slice maxEnding = 0 maxSlice = 0 …
Question app.codility.com My Solution app.codility.com def solution(A): # check if A has a dominator length = len(A) stack = [0]*length size = 0 for i in range(length): if size == 0: stack[size] = A[i] size += 1 elif stack[size-1] != A[i]:…
Question app.codility.com My Solution app.codility.com def solution(A): stack = [0]*len(A) size = 0 index = -1 count = 0 for i in range(len(A)): if size == 0: stack[size] = A[i] size += 1 else: if stack[size-1] != A[i]: size -= 1 else: sta…
Question app.codility.com My Solution app.codility.com def solution(H): block = 0 stack = [0]*len(H) size = 0 for i in range(len(H)): while size > 0 and stack[size-1] > H[i]: size -= 1 if size > 0 and stack[size-1] == H[i]: pass else: bloc…
Question app.codility.com My Solution app.codility.com def solution(S): stack = [0]*len(S) size = 0 for i in range(len(S)): if S[i] is "(": stack[size] = S[i] size += 1 else: if size is 0: return 0 else: size -= 1 if size is 0: return 1 re…
Question app.codility.com My Solution app.codility.com def solution(S): stack = [0]*len(S) size = 0 for i in range(len(S)): if S[i] is "(" or S[i] is "{" or S[i] is "[": stack[size] = S[i] size += 1 else: if size is 0: return 0 elif S[i] i…
Notice Recently I got some codility challenges from companies and they don't allow me to use javascript. As a results, I learn the basic coding style in python from the very beginning on YouTube Python Programming Tutorial - 1 - Installing…
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; }
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…
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…
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…
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…
Question app.codility.com My Solution app.codility.com function solution(S, P, Q) { let prefixASum = []; let prefixCSum = []; let prefixGSum = []; let prefixTSum = []; let ASum = 0; let CSum = 0; let GSum = 0; let TSum = 0; let ans = []; f…
Question app.codility.com My Solution app.codility.com function solution(A) { let suffixSum = []; let sum = 0; let ans = 0; for (let i = A.length-1; i >= 0; i--) { sum += A[i]; suffixSum[i] = sum; } for (let i = 0; i < A.length; i++) { if …
Question app.codility.com My Solution app.codility.com function solution(A) { let count = []; let minMissing = 0; for (let i = 0; i < A.length; i++) { if (A[i] > 0) { if (count[A[i]] === undefined) { count[A[i]] = 1; } while (count[minMiss…
Question app.codility.com Solution app.codility.com function solution(N, A) { let setMax = 0; let knownMax = 0; let currentMax = 0; let count = []; for (let i = 0; i < N; i++) { count[i] = 0; } for (let i = 0; i < A.length; i++) { if (A[i] …
Question app.codility.com My Solution app.codility.com function solution(X, A) { let count = []; let maxDist = 0; for (let i = 0; i < A.length; i++) { if (count[A[i]] === undefined) count[A[i]] = 1; while(count[maxDist+1] === 1) maxDist++;…
Question app.codility.com My Solution app.codility.com function solution(A) { let count = []; for (let i = 0; i < A.length; i++) { if (A[i] > A.length+1) return 0; if (count[A[i]-1] === undefined) count[A[i]-1] = 1; else return 0; } for (l…
Question app.codility.com My Solution (O(n)) app.codility.com function solution(A) { let prefixSum = []; let suffixSum = []; prefixSum[0] = A[0]; for (let i = 1; i < A.length; i++) { prefixSum[i] = prefixSum[i-1]+A[i]; } suffixSum[A.length…
Question app.codility.com My Solution app.codility.com function solution(A) { if (A.length === 0) return 1; let arrSum = A.reduce( (prev, curr) => prev + curr ); let permSum = (1 + A.length + 1)*(A.length + 1)/2; return permSum-arrSum; } N…
Question app.codility.com My Solution app.codility.com function solution(X, Y, D) { return Math.ceil((Y-X)/D); }
brew upgrade node brew link node
Question app.codility.com My Solution (O(nlogn)) app.codility.com function solution(A) { A.sort((a, b)=>(a-b)); for (let i = 0; i < A.length; i+=2) { if (A[i] != A[i+1]) { return A[i]; } } } Online Solution (O(n)) Odd Occurrences In Array …