This file contains hidden or 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
// | |
// Compute string similarity using Levenshtein distance algorithm | |
// | |
// See: https://en.wikipedia.org/wiki/Levenshtein_distance | |
// | |
/** | |
* @param {string} a - The first string | |
* @param {string} b - The second string | |
* @return {number} - An integer representation of the difference |
This file contains hidden or 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
// | |
// Build a Xbonacci function that takes a signature of X elements - and | |
// remember each next element is the sum of the last X elements - and | |
// returns the first n elements of the so seeded sequence. | |
// | |
// xbonacci([1,1,1,1],10) -> [1,1,1,1,4,7,13,25,49,94] | |
// xbonacci([0,0,0,0,1],10) -> [0,0,0,0,1,1,2,4,8,16] | |
// xbonacci([1,0,0,0,0,0,1],10) -> [1,0,0,0,0,0,1,1,2,4] | |
// |
This file contains hidden or 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
// | |
// Example filters | |
// - will populate a dropdown <select> | |
// - has an optional useKeywordFilter flag | |
// | |
const losFilters = { | |
key: 'lineOfService', | |
label: 'Line of Service', |
This file contains hidden or 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
// | |
// See: http://careercup.com/question?id=16759664 | |
// | |
// You have k lists of sorted integers. Find the smallest range | |
// that includes at least one number from each of the k lists. | |
// | |
// Input: [[4, 10, 15, 24, 26], [0, 9, 12, 20], [5, 18, 22, 30]] | |
// Output: [20, 24] | |
// |
This file contains hidden or 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
// | |
// See: http://careercup.com/question?id=11070934 | |
// | |
// Given an array which might contain duplicates, find | |
// largest subset of it which forms subsequence | |
// | |
// Input: [1, 6, 10, 4, 7, 9, 5] | |
// Output: [4, 5, 6, 7] | |
// |
This file contains hidden or 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
// | |
// See: http://careercup.com/question?id=5201559730257920 | |
// | |
// Given an array which has positive and negative ints, sort | |
// the list so that all positives come after negatives, and the | |
// relative order is preserved. | |
// | |
// Input: [-1, 2, 2, -2, -3, 1, 10, 9, -9] | |
// Output: [-1, -2, -3, -9, 2, 2, 1, 10, 9] | |
// |
This file contains hidden or 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
// Given an array where all numbers except one are repeated, | |
// find the number that only occurs once. | |
const uniqNums = function(list) { | |
let hash = {}; | |
let uniq = {}; | |
// O(n) - iterate through list | |
for (let i = 0; i < list.length; i++) { | |
if (hash.hasOwnProperty(list[i])) { | |
delete uniq[list[i]]; |
This file contains hidden or 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
// | |
// See: http://careercup.com/question?id=5755014750404608 | |
// | |
// Input: [[1,3], [5,7], [2,4], [6,8]] | |
// Output: [[1,4], [5,8]] (no specific order) | |
// | |
var mergeRanges = (function () { | |
/** |
This file contains hidden or 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
// | |
// See: http://careercup.com/question?id=4816567298686976 | |
// | |
'use strict'; | |
// var set = [2, 3], n = 8; | |
// expect: results.exp = [1, 2, 3, 4, 6, 8, 9, 12] | |
// expect: results.non = [5, 7, 10, 11] |
This file contains hidden or 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
// | |
// See: http://www.glassdoor.com/Interview/You-are-given-a-collection-of-M-arrays-with-N-integers-Every-array-is-sorted-Develop-an-algorithm-to-combine-each-array-i-QTN_1195702.htm | |
// | |
// You are given a collection of M arrays with N integers. Every array is sorted. | |
// Develop an algorithm to combine each array into one sorted array. | |
// | |
var mergeSortedLists = (function () { | |
/** |