Skip to content

Instantly share code, notes, and snippets.

View divmgl's full-sized avatar

Dexter Miguel divmgl

  • San Francisco, CA
  • 06:58 (UTC -12:00)
View GitHub Profile
@divmgl
divmgl / permcheck.js
Created December 1, 2015 06:09
PermCheck Javascript 100%/100%
function solution(A) {
var L = A.length; // Length of the array
var X = ((L + 1) * L) / 2; // Sum from 1..L
var Y = 0; // Sum of evaluated values
var I = 0; // Counter
var F = []; // Found elements
var V = -1; // Container
while (I < L) { // Start searching the array
V = A[I]; // Get the value
@divmgl
divmgl / frogriverone.js
Created December 1, 2015 05:50
FrogRiverOne JavaScript solution 100%/100%
function solution(X, A) {
if (A.length === 1) { // If the array is one element
// And if its first item is 1 as well as the value to search for,
// the frog doesn't need to move
if (A[0] === 1 && X === 1) return 0;
// If not, it's impossible to go anywhere
else return -1;
}
var i = -1, // Counter