This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var array = [1, 3, 5, 7, 9, 10, 22, 33, 45, 67, 88, 90]; | |
function binarySearch(array, num) { | |
if (array.length < 1) { | |
return -1; | |
} | |
var low = 0; | |
var hi = array.length-1; | |
while (hi >= low) { | |
var mid = Math.floor((low + hi) / 2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function readFileContent($filename) { | |
$result = FALSE; | |
if (file_exists($filename)) { | |
$result = file($filename, FILE_SKIP_EMPTY_LINES); | |
} | |
return $result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function twoSum(data) { | |
var count = 0; | |
for (var i = 0; i < data.length; i++) { | |
for (var j = i+1; j < data.length; j++) { | |
if (data[i] + data[j] === 0) { | |
count++; | |
} | |
} | |
} | |
return count; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A binary gap within a positive integer N is any maximal sequence of consecutive zeros | |
# that is surrounded by ones at both ends in the binary representation of N. | |
# For example, number 9 has binary representation 1001 and contains a binary gap of length 2. | |
# The number 529 has binary representation 1000010001 and contains two binary gaps: one of length 4 and one of length 3. | |
# The number 20 has binary representation 10100 and contains one binary gap of length 1. | |
# The number 15 has binary representation 1111 and has no binary gaps. that, given a positive integer N, | |
# returns the length of its longest binary gap. | |
# The function should return 0 if N doesn't contain a binary gap. | |
# For example, given N = 1041 the function should return 5, because N has binary representation 10000010001 and so its longest |
NewerOlder