Skip to content

Instantly share code, notes, and snippets.

View herberthk's full-sized avatar
🏠
Full stack developer

Kavuma Herbert herberthk

🏠
Full stack developer
View GitHub Profile
@jeanlescure
jeanlescure / TapeEquilibrium.js
Last active September 2, 2022 13:57
Codility TapeEquilibrium Solution in Javascript - 100% score
/*
A non-empty zero-indexed array A consisting of N integers is given. Array A represents numbers on a tape.
Any integer P, such that 0 < P < N, splits this tape into two non-empty parts: A[0], A[1], ..., A[P − 1] and A[P], A[P + 1], ..., A[N − 1].
The difference between the two parts is the value of: |(A[0] + A[1] + ... + A[P − 1]) − (A[P] + A[P + 1] + ... + A[N − 1])|
In other words, it is the absolute difference between the sum of the first part and the sum of the second part.
*/
@jonataswalker
jonataswalker / codility_solutions.txt
Created May 21, 2016 10:11 — forked from lalkmim/codility_solutions.txt
Codility Solutions in JavaScript
Lesson 1 - Iterations
- BinaryGap - https://codility.com/demo/results/trainingU2FQPQ-7Y4/
Lesson 2 - Arrays
- OddOccurrencesInArray - https://codility.com/demo/results/trainingFN5RVT-XQ4/
- CyclicRotation - https://codility.com/demo/results/trainingSH2W5R-RP5/
Lesson 3 - Time Complexity
- FrogJmp - https://codility.com/demo/results/training6KKWUD-BXJ/
- PermMissingElem - https://codility.com/demo/results/training58W4YJ-VHA/
@balazsnemeth
balazsnemeth / gist:352e3230a0868ea811817e919a044f07
Last active March 25, 2021 06:27
Solution for Count Non Divisible
// Solution for CountNonDivisible (Codility)
// Not the best, just O(N^2)...
// https://codility.com/programmers/lessons/11-sieve_of_eratosthenes/count_non_divisible/
function solution(A) {
// write your code in JavaScript (Node.js 6.4.0)
const divisors = A.map(e => 0);
for (let i = 0; i<A.length; i++) {
@anabastos
anabastos / umbrella.js
Last active May 28, 2021 18:53
Umbrella.js
//Solution of https://gist.github.com/lubien/1f09a53a4b5607377166c58a7eb49ae0
const solve = (people, umbrellas) => {
const biggerUmbrella = Math.max(...umbrellas)
const remain = people % biggerUmbrella
const peopleThatFit = Math.floor(people / biggerUmbrella)
if (remain >= 1 && umbrellas.length === 1) {
return -1
} else {
@k0ff33
k0ff33 / OddOccurrencesInArray.js
Last active March 30, 2022 15:59
Odd Occurrences In Array exercise from Codility (JavaScript/NodeJS)
/**
* Finds element without a pair in an unsorted array of integers
* @param {array} A
* @return {int} element without a pair
*/
function solution(A) {
let result = 0;
for (let element of A) {
// Apply Bitwise XOR to the current and next element
@matheushf
matheushf / FrogRiverOne.js
Created January 8, 2018 18:44
Javascript solution for the Codility Frog River One
function solution(X, A) {
// write your code in JavaScript (Node.js 6.4.0)
let sequence = [0];
let position = -1;
let counter = 0;
if (X === 1 && A[0] === 1)
return 0;
@steven2358
steven2358 / ffmpeg.md
Last active July 22, 2024 08:40
FFmpeg cheat sheet
@lienista
lienista / 242-leetcode-valid-anagram.js
Last active February 25, 2021 05:35
(Algorithms in Javascript) Leetcode 242. Valid Anagram - Given two strings s and t , write a function to determine if t is an anagram of s.
const isAnagram => (s, t) {
var lens = s.length,
lent = t.length;
if(lens !== lent) return false;
if(typeof s !== 'string' || typeof t !== 'string') return false;
if(lens === 0 && lent === 0) return true;
var charmap = {};
for(let i=0; i<lens; i++){
charmap[s[i]] = charmap[s[i]] ? charmap[s[i]]+1: 1;
@bradtraversy
bradtraversy / sample.md
Created March 23, 2018 18:17
Markdown Cheat Sheet

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

This text is italic

@lasverg
lasverg / diagonal-difference.js
Last active May 29, 2023 06:34
Diagonal Difference | Solution | JavaScript
/*
Diagonal Difference Solution.
sample matrix = [[1,2,3], [4,5,6], [7,8,9]]
*/
function diagonalDifference(matrix) {
// length of input matrix.
const length = matrix.length;
let diagonal1 = 0, diagonal2 = 0;
// Looping through the array and summing the diagonals.