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 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 |
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
#include <iostream> | |
#include <array> | |
#include <map> | |
#include <random> | |
using std::cout; | |
using std::endl; | |
using std::string; | |
using std::array; |
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
def solution(A): | |
table = dict() | |
for num in A: | |
if not table.get(num): | |
table[num] = 1 | |
else: | |
table.pop(num) | |
return table.keys()[0] |
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
def solution(A, K): | |
if len(A) == 0: | |
return A | |
for _ in range(K): | |
A.insert(0, A.pop()) | |
return A |
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
import math | |
def solution(X, Y, D): | |
return int(math.ceil(float(Y - X) / float(D))) |
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
def solution(A): | |
total = sum(A) | |
diff = sum(range(1, len(A) + 2)) | |
return abs(diff - total) |
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
def solution(N): | |
max = 0 | |
bits = 0 | |
bin = "{0:b}".format(N) | |
for c in bin: | |
if c == "0": | |
bits += 1 | |
if c == "1": | |
if max < bits: |
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 solution(A) { | |
var F = []; // Found list | |
var I = 0, V = 0; // Counter, container | |
while (I < A.length) { // Iterate through the array | |
V = A[I]; // Store the value | |
I++; // Increase counter | |
if (F[V]) continue; // If the value exists, continue | |
F[V] = true; // Store the value | |
} |
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 solution(N, A) { | |
var M = A.length; // Length of the entry array | |
var C = []; // Counters | |
var H = 0; // Highest counter | |
var PH = 0; // Previously recorded highest counter | |
for(K = 0; K < N; K++) { // Initialize the array | |
C[K] = 0; | |
} | |
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 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 |
OlderNewer