You are given two non-empty arrays A and B consisting of N integers. These arrays represent N planks. More precisely, A[K] is the start and B[K] the end of the K−th plank.
Next, you are given a non-empty array C consisting of M integers. This array represents M nails. More precisely, C[I] is the position where you can hammer in the I−th nail.
We say that a plank (A[K], B[K]) is nailed if there exists a nail C[I] such that A[K] ≤ C[I] ≤ B[K].
The goal is to find the minimum number of nails that must be used until all the planks are nailed. In other words, you should find a value J such that all planks will be nailed after using only the first J nails. More precisely, for every plank (A[K], B[K]) such that 0 ≤ K < N, there should exist a nail C[I] such that I < J and A[K] ≤ C[I] ≤ B[K].
For example, given arrays A, B such that:
A[0] = 1 B[0] = 4 A[1] = 4 B[1] = 5 A[2] = 5 B[2] = 9 A[3] = 8 B[3] = 10four planks are represented: [1, 4], [4, 5], [5, 9] and [8, 10].
Given array C such that:
C[0] = 4 C[1] = 6 C[2] = 7 C[3] = 10 C[4] = 2if we use the following nails:
- 0, then planks [1, 4] and [4, 5] will both be nailed.
- 0, 1, then planks [1, 4], [4, 5] and [5, 9] will be nailed.
- 0, 1, 2, then planks [1, 4], [4, 5] and [5, 9] will be nailed.
- 0, 1, 2, 3, then all the planks will be nailed.
Thus, four is the minimum number of nails that, used sequentially, allow all the planks to be nailed.
Write a function:
function solution(A, B, C);
that, given two non-empty arrays A and B consisting of N integers and a non-empty array C consisting of M integers, returns the minimum number of nails that, used sequentially, allow all the planks to be nailed.
If it is not possible to nail all the planks, the function should return −1.
For example, given arrays A, B, C such that:
A[0] = 1 B[0] = 4 A[1] = 4 B[1] = 5 A[2] = 5 B[2] = 9 A[3] = 8 B[3] = 10 C[0] = 4 C[1] = 6 C[2] = 7 C[3] = 10 C[4] = 2the function should return 4, as explained above.
Write an efficient algorithm for the following assumptions:
- N and M are integers within the range [1..30,000];
- each element of arrays A, B and C is an integer within the range [1..2*M];
- A[K] ≤ B[K].
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
for (let)
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
let totalNails = Array.from({ length = maxB})
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
let totalNails = Array.from({ length: maxB})
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
let totalNails = Array.from({ length: maxB+1}, () => 0)
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
let totalNails = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid =
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
let totalNails = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
for (let i = 0; )
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
for (let i = 0; )
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
f
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
for (let i = 0; i < mid; i++) {
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
for (let i = 0; i < mid; i++) {
t
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
for (let i = 0; i < mid; i++) {
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, (v,i) => 0);
for (let i = 0; i < mid; i++) {
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, (v,i) => i < mid ? 0 : 1);
for (let i = 0; i < mid; i++) {
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, (v,i) => i < mid ? 0 : 1);
for (let i = 0; i < totalNails.length; i++) {
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, (v,i) => i < mid ? 0 : 1);
for (let i = 1; i < totalNails.length; i++) {
totalNails[]
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
for (let i = 0; i < mid; i++) {
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < )
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
}
}
function
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
le
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
}
}
function
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
}
}
function
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
}
}
function
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length, )
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length, i++) {
if (totalNails[A[i] - 1] === totalNails)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length, i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result =
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length, i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
}
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length, i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible =
}
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length, i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
max = mid;
} else {
}
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length, i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
max = mid;
} else {
min = mid + 1;
}
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length, i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
max = mid;
} else {
min = mid + 1;
}
}
if (possible) {
return min;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length, i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
solution.js:50 for (let i = 0; i < A.length, i++) { ^ SyntaxError: Unexpected token ) at createScript (vm.js:80:10) at Object.runInNewContext (vm.js:135:10) at getSolution (/tmp/exec.js:412:29) at Promise.resolve.then (/tmp/exec.js:446:34) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
max = mid;
} else {
min = mid + 1;
}
}
if (possible) {
return min;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = Array.from({ length: maxB+1}, () => 0);
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
max = mid;
} else {
min = mid + 1;
}
}
if (possible) {
return min;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
max = mid;
} else {
min = mid + 1;
}
}
if (possible) {
return min;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
let totalNails = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
max = mid;
} else {
min = mid + 1;
}
}
if (possible) {
return min;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
let totalNails = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
max = mid;
} else {
min = mid + 1;
}
}
if (possible) {
return min;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
let totalNails = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
max = mid;
} else {
min = mid + 1;
}
}
if (possible) {
return min;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
let totalNails = totalNailsInitial
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
max = mid;
} else {
min = mid + 1;
}
}
if (possible) {
return min;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = totalNailsInitial
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
max = mid;
} else {
min = mid + 1;
}
}
if (possible) {
return min;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = totalNailsInitial
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
max = mid;
} else {
min = mid + 1;
}
}
if (possible) {
return min;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:')
let totalNails = totalNailsInitial
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
max = mid;
} else {
min = mid + 1;
}
}
if (possible) {
return min;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
max = mid;
} else {
min = mid + 1;
}
}
if (possible) {
return min;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
-> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg, end, mid: 0 5 3 -> beg,
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
co
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
max = mid;
} else {
min = mid + 1;
}
}
if (possible) {
return min;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
console.log(totalNails)
let result = checkNailed(A, B, totalNails);
console.log(result)
if (result) {
possible = true;
if (end === mid) {
break;
}
max = mid;
} else {
min = mid + 1;
}
}
if (possible) {
return min;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
console.log(totalNails)
let result = checkNailed(A, B, totalNails);
console.log(result)
if (result) {
possible = true;
if (end === mid) {
break;
}
max = mid;
} else {
min = mid + 1;
}
}
if (possible) {
return min;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
-> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 ] false -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 2, 3, 4, 7, 10, 13 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 3, 4, 5, 12, 22, 35 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 4, 5, 6, 18, 40, 75 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 5, 6, 7, 25, 65, 140 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 6, 7, 8, 33, 98, 238 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 7, 8, 9, 42, 140, 378 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 8, 9, 10, 52, 192, 570 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 9, 10, 11, 63, 255, 825 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 10, 11, 12, 75, 330, 1155 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 11, 12, 13, 88, 418, 1573 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 12, 13, 14, 102, 520, 2093 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 13, 14, 15, 117, 637, 2730 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 14, 15, 16, 133, 770, 3500 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 15, 16, 17, 150, 920, 4420 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 16, 17, 18, 168, 1088, 5508 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 17, 18, 19, 187, 1275, 6783 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 18, 19, 20, 207, 1482, 8265 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 19, 20, 21, 228, 1710, 9975 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 20, 21, 22, 250, 1960, 11935 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 21, 22, 23, 273, 2233, 14168 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 22, 23, 24, 297, 2530, 16698 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 23, 24, 25, 322, 2852, 19550 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 24, 25, 26, 348, 3200, 22750 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 25, 26, 27, 375, 3575, 26325 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 26, 27, 28, 403, 3978, 30303 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 27, 28, 29, 432, 4410, 34713 ] true -> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 28, 29, 30, 462, 48
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
console.log(totalNails)
let result = checkNailed(A, B, totalNails);
console.log(result)
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid + 1;
}
}
if (possible) {
return min;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
ReferenceError: min is not defined at solution (solution.js:49:9) at solutionWrapper (/tmp/exec.js:422:28) at Promise.resolve.then (/tmp/exec.js:448:24) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3stdout:
-> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 ] false -> beg, end, mid: 4 5 5 [ 0, 0, 1, 1, 2, 3, 4, 5, 8, 11, 12 ] true
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
console.log(totalNails)
let result = checkNailed(A, B, totalNails);
console.log(result)
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid + 1;
}
}
if (possible) {
return beg;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
console.log(totalNails)
let result = checkNailed(A, B, totalNails);
console.log(result)
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid + 1;
}
}
if (possible) {
return beg;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
-> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 ] false -> beg, end, mid: 4 5 5 [ 0, 0, 1, 1, 2, 3, 4, 5, 8, 11, 12 ] true
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
console.log(totalNails)
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
console.log(totalNails)
let result = checkNailed(A, B, totalNails);
console.log(result)
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid + 1;
}
}
if (possible) {
return beg;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
console.log(totalNails);
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
console.log(totalNails)
let result = checkNailed(A, B, totalNails);
console.log(result)
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid + 1;
}
}
if (possible) {
return beg;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
-> beg, end, mid: 0 5 3 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] [ 0, 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 ] false -> beg, end, mid: 4 5 5 [ 0, 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 ] [ 0, 0, 1, 1, 2, 3, 4, 5, 8, 11, 12 ] true
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
console.log(totalNails);
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
console.log(totalNails)
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid + 1;
}
}
if (possible) {
return beg;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid + 1;
}
}
if (possible) {
return beg;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid + 1;
}
}
if (possible) {
return beg;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
-> beg, end, mid: 0 5 3 -> beg, end, mid: 4 5 5
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid + 1;
}
}
if (possible) {
return beg;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid + 1;
}
}
if (possible) {
return beg;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
[[1], [2], [3]]
-> beg, end, mid: 0 5 3 -> beg, end, mid: 4 5 5
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid + 1;
}
}
if (possible) {
return beg;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
[[1], [2], [3]]
[[1], [2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3]]
-> beg, end, mid: 0 5 3 -> beg, end, mid: 4 5 5
function result: -1
function result: 0
-> beg, end, mid: 0 12 6 -> beg, end, mid: 0 6 3 -> beg, end, mid: 0 3 2 -> beg, end, mid: 0 2 1 -> beg, end, mid: 0 1 1
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
if (possible) {
return beg;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
if (possible) {
return beg+1;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
[[1], [2], [3]]
[[1], [2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3]]
-> beg, end, mid: 0 5 3 -> beg, end, mid: 3 5 4 -> beg, end, mid: 3 4 4
function result: -1
function result: 1
-> beg, end, mid: 0 12 6 -> beg, end, mid: 0 6 3 -> beg, end, mid: 0 3 2 -> beg, end, mid: 0 2 1 -> beg, end, mid: 0 1 1
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
if (possible) {
return beg+1;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
[[1], [2], [3]]
[[1], [2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3]]
-> beg, end, mid: 0 5 3 -> beg, end, mid: 3 5 4 -> beg, end, mid: 3 4 4
function result: -1
function result: 1
-> beg, end, mid: 0 12 6 -> beg, end, mid: 0 6 3 -> beg, end, mid: 0 3 2 -> beg, end, mid: 0 2 1 -> beg, end, mid: 0 1 1
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
if (possible) {
return beg+1;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
if (possible) {
return beg+1;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
if (possible) {
return beg+1;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
[[1], [2], [3]]
[[1], [2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3]]
[[1], [2], [3, 3, 3, 3, 3, 3, 3, 3, 3, 2]]
-> beg, end, mid: 0 5 3 -> beg, end, mid: 3 5 4 -> beg, end, mid: 3 4 4
function result: -1
function result: 1
-> beg, end, mid: 0 12 6 -> beg, end, mid: 0 6 3 -> beg, end, mid: 0 3 2 -> beg, end, mid: 0 2 1 -> beg, end, mid: 0 1 1
function result: 10
-> beg, end, mid: 0 10 5 -> beg, end, mid: 5 10 8 -> beg, end, mid: 8 10 9 -> beg, end, mid: 9 10 10
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
if (possible) {
return beg+1;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
if (possible) {
return beg+1;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
if (possible) {
return beg+1;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
if (possible) {
return beg+1;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
[[1], [2], [3]]
[[1], [2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3]]
[[1], [2], [3, 3, 3, 3, 3, 3, 3, 3, 3, 2]]
[[1, 2, 1], [2, 3, 30000], [3, 1, 2]]
-> beg, end, mid: 0 5 3 -> beg, end, mid: 3 5 4 -> beg, end, mid: 3 4 4
function result: -1
function result: 1
-> beg, end, mid: 0 12 6 -> beg, end, mid: 0 6 3 -> beg, end, mid: 0 3 2 -> beg, end, mid: 0 2 1 -> beg, end, mid: 0 1 1
function result: 10
-> beg, end, mid: 0 10 5 -> beg, end, mid: 5 10 8 -> beg, end, mid: 8 10 9 -> beg, end, mid: 9 10 10
function result: 1
-> beg, end, mid: 0 3 2 -> beg, end, mid: 0 2 1 -> beg, end, mid: 0 1 1
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
if (possible) {
return end;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
if (possible) {
return end;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true
}
[[1], [2], [3]]
[[1], [2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3]]
[[1], [2], [3, 3, 3, 3, 3, 3, 3, 3, 3, 2]]
[[1, 2, 1], [2, 3, 30000], [3, 1, 2]]
-> beg, end, mid: 0 5 3 -> beg, end, mid: 3 5 4 -> beg, end, mid: 3 4 4
function result: -1
function result: 1
-> beg, end, mid: 0 12 6 -> beg, end, mid: 0 6 3 -> beg, end, mid: 0 3 2 -> beg, end, mid: 0 2 1 -> beg, end, mid: 0 1 1
function result: 10
-> beg, end, mid: 0 10 5 -> beg, end, mid: 5 10 8 -> beg, end, mid: 8 10 9 -> beg, end, mid: 9 10 10
function result: 1
-> beg, end, mid: 0 3 2 -> beg, end, mid: 0 2 1 -> beg, end, mid: 0 1 1
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
if (possible) {
return end;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
let lastPossible = 0;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
if (possible) {
return end;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let possible = false;
let lastPossible = 0;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
possible = true;
lastPossible =
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
if (possible) {
return end;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
lastPossible = mid + 1;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
if (possible) {
return end;
} else {
return -1;
}
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
lastPossible = mid + 1;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
[[1], [2], [3]]
[[1], [2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3]]
[[1], [2], [3, 3, 3, 3, 3, 3, 3, 3, 3, 2]]
[[1, 2, 1], [2, 3, 30000], [3, 1, 2]]
-> beg, end, mid: 0 5 3 -> beg, end, mid: 3 5 4 -> beg, end, mid: 3 4 4
function result: -1
function result: 2
-> beg, end, mid: 0 12 6 -> beg, end, mid: 0 6 3 -> beg, end, mid: 0 3 2 -> beg, end, mid: 0 2 1 -> beg, end, mid: 0 1 1
function result: 11
-> beg, end, mid: 0 10 5 -> beg, end, mid: 5 10 8 -> beg, end, mid: 8 10 9 -> beg, end, mid: 9 10 10
function result: 2
-> beg, end, mid: 0 3 2 -> beg, end, mid: 0 2 1 -> beg, end, mid: 0 1 1
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
[[1], [2], [3]]
[[1], [2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3]]
[[1], [2], [3, 3, 3, 3, 3, 3, 3, 3, 3, 2]]
[[1, 2, 1], [2, 3, 30000], [3, 1, 2]]
-> beg, end, mid: 0 5 3 -> beg, end, mid: 3 5 4 -> beg, end, mid: 3 4 4
function result: -1
function result: 1
-> beg, end, mid: 0 12 6 -> beg, end, mid: 0 6 3 -> beg, end, mid: 0 3 2 -> beg, end, mid: 0 2 1 -> beg, end, mid: 0 1 1
function result: 10
-> beg, end, mid: 0 10 5 -> beg, end, mid: 5 10 8 -> beg, end, mid: 8 10 9 -> beg, end, mid: 9 10 10
function result: 1
-> beg, end, mid: 0 3 2 -> beg, end, mid: 0 2 1 -> beg, end, mid: 0 1 1
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
cosn
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
console.log()
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
let result = checkNailed(A, B, totalNails);
if (result) {
console.log('res')
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
console.log('!res')
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
console.log('-> beg, end, mid:', beg, end, mid)
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
console.log(totalNails)
let result = checkNailed(A, B, totalNails);
if (result) {
console.log('res')
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
console.log('!res')
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
console.log(totalNails)
let result = checkNailed(A, B, totalNails);
if (result) {
console.log('res')
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
console.log('!res')
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
console.log('-> beg, end, mid, nails:', beg, end, mid, totalNails)
let result = checkNailed(A, B, totalNails);
if (result) {
console.log('res')
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
console.log('!res')
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
[[1], [2], [3]]
[[1], [2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3]]
[[1], [2], [3, 3, 3, 3, 3, 3, 3, 3, 3, 2]]
[[1, 2, 1], [2, 3, 30000], [3, 1, 2]]
-> beg, end, mid, nails: 0 5 3 [ 0, 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 ] !res -> beg, end, mid, nails: 3 5 4 [ 0, 0, 0, 0, 1, 2, 3, 4, 7, 10, 11 ] res -> beg, end, mid, nails: 3 4 4 [ 0, 0, 0, 0, 1, 3, 4, 5, 12, 22, 23 ] res
function result: -1
function result: 1
-> beg, end, mid, nails: 0 12 6 [ 0, 1, 1 ] res -> beg, end, mid, nails: 0 6 3 [ 0, 1, 2 ] res -> beg, end, mid, nails: 0 3 2 [ 0, 1, 3 ] res -> beg, end, mid, nails: 0 2 1 [ 0, 1, 4 ] res -> beg, end, mid, nails: 0 1 1 [ 0, 1, 5 ] res
function result: 10
-> beg, end, mid, nails: 0 10 5 [ 0, 0, 0, 1 ] !res -> beg, end, mid, nails: 5 10 8 [ 0, 0, 0, 1 ] !res -> beg, end, mid, nails: 8 10 9 [ 0, 0, 0, 1 ] !res -> beg, end, mid, nails: 9 10 10 [ 0, 0, 1, 1 ] res
function result: 1
-> beg, end, mid, nails: 0 3 2 [ 0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ... 29901 more items ] res -> beg, end, mid, nails: 0 2 1 [ 0, 1, 2, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 157, 159, 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 189, 191, 193, 195, ... 29901 more items ] res -> beg, end, mid, nails: 0 1 1 [ 0, 1, 3, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249, 3364, 3481, 3600, 3721, 3844, 3969, 4096, 4225, 4356, 4489, 4624, 4761, 4900, 5041, 5184, 5329, 5476, 5625, 5776, 5929, 6084, 6241, 6400, 6561, 6724, 6889, 7056, 7225, 7396, 7569, 7744, 7921, 8100, 8281, 8464, 8649, 8836, 9025, 9216, 9409, 9604, ...
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
console.log('-> beg, end, mid, nails:', beg, end, mid, totalNails)
let result = checkNailed(A, B, totalNails);
if (result) {
console.log('res')
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
console.log('!res')
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = totalNailsInitial;
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
console.log('-> beg, end, mid, nails:', beg, end, mid, totalNails)
let result = checkNailed(A, B, totalNails);
if (result) {
console.log('res')
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
console.log('!res')
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
[[1], [2], [3]]
[[1], [2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3]]
[[1], [2], [3, 3, 3, 3, 3, 3, 3, 3, 3, 2]]
[[1, 2, 1], [2, 3, 10], [3, 1, 2]]
-> beg, end, mid, nails: 0 5 3 [ 0, 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 ] !res -> beg, end, mid, nails: 3 5 4 [ 0, 0, 0, 0, 1, 2, 3, 4, 7, 10, 11 ] res -> beg, end, mid, nails: 3 4 4 [ 0, 0, 0, 0, 1, 3, 4, 5, 12, 22, 23 ] res
function result: -1
function result: 1
-> beg, end, mid, nails: 0 12 6 [ 0, 1, 1 ] res -> beg, end, mid, nails: 0 6 3 [ 0, 1, 2 ] res -> beg, end, mid, nails: 0 3 2 [ 0, 1, 3 ] res -> beg, end, mid, nails: 0 2 1 [ 0, 1, 4 ] res -> beg, end, mid, nails: 0 1 1 [ 0, 1, 5 ] res
function result: 10
-> beg, end, mid, nails: 0 10 5 [ 0, 0, 0, 1 ] !res -> beg, end, mid, nails: 5 10 8 [ 0, 0, 0, 1 ] !res -> beg, end, mid, nails: 8 10 9 [ 0, 0, 0, 1 ] !res -> beg, end, mid, nails: 9 10 10 [ 0, 0, 1, 1 ] res
function result: 1
-> beg, end, mid, nails: 0 3 2 [ 0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2 ] res -> beg, end, mid, nails: 0 2 1 [ 0, 1, 2, 3, 5, 7, 9, 11, 13, 15, 17 ] res -> beg, end, mid, nails: 0 1 1 [ 0, 1, 3, 4, 9, 16, 25, 36, 49, 64, 81 ] res
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = totalNailsInitial;
co
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
console.log('-> beg, end, mid, nails:', beg, end, mid, totalNails)
let result = checkNailed(A, B, totalNails);
if (result) {
console.log('res')
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
console.log('!res')
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = totalNailsInitial;
console.log(totalNails)
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
console.log('-> beg, end, mid, nails:', beg, end, mid, totalNails)
let result = checkNailed(A, B, totalNails);
if (result) {
console.log('res')
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
console.log('!res')
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
[[1], [2], [3]]
[[1], [2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3]]
[[1], [2], [3, 3, 3, 3, 3, 3, 3, 3, 3, 2]]
[[1, 2, 1], [2, 3, 10], [3, 1, 2]]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] -> beg, end, mid, nails: 0 5 3 [ 0, 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 ] !res [ 0, 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 ] -> beg, end, mid, nails: 3 5 4 [ 0, 0, 0, 0, 1, 2, 3, 4, 7, 10, 11 ] res [ 0, 0, 0, 0, 1, 2, 3, 4, 7, 10, 11 ] -> beg, end, mid, nails: 3 4 4 [ 0, 0, 0, 0, 1, 3, 4, 5, 12, 22, 23 ] res
function result: -1
function result: 1
[ 0, 0, 0 ] -> beg, end, mid, nails: 0 12 6 [ 0, 1, 1 ] res [ 0, 1, 1 ] -> beg, end, mid, nails: 0 6 3 [ 0, 1, 2 ] res [ 0, 1, 2 ] -> beg, end, mid, nails: 0 3 2 [ 0, 1, 3 ] res [ 0, 1, 3 ] -> beg, end, mid, nails: 0 2 1 [ 0, 1, 4 ] res [ 0, 1, 4 ] -> beg, end, mid, nails: 0 1 1 [ 0, 1, 5 ] res
function result: 10
[ 0, 0, 0 ] -> beg, end, mid, nails: 0 10 5 [ 0, 0, 0, 1 ] !res [ 0, 0, 0, 1 ] -> beg, end, mid, nails: 5 10 8 [ 0, 0, 0, 1 ] !res [ 0, 0, 0, 1 ] -> beg, end, mid, nails: 8 10 9 [ 0, 0, 0, 1 ] !res [ 0, 0, 0, 1 ] -> beg, end, mid, nails: 9 10 10 [ 0, 0, 1, 1 ] res
function result: 1
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] -> beg, end, mid, nails: 0 3 2 [ 0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2 ] res [ 0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2 ] -> beg, end, mid, nails: 0 2 1 [ 0, 1, 2, 3, 5, 7, 9, 11, 13, 15, 17 ] res [ 0, 1, 2, 3, 5, 7, 9, 11, 13, 15, 17 ] -> beg, end, mid, nails: 0 1 1 [ 0, 1, 3, 4, 9, 16, 25, 36, 49, 64, 81 ] res
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = totalNailsInitial.slic;
console.log(totalNails)
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
console.log('-> beg, end, mid, nails:', beg, end, mid, totalNails)
let result = checkNailed(A, B, totalNails);
if (result) {
console.log('res')
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
console.log('!res')
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = totalNailsInitial.slice();
console.log(totalNails)
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
console.log('-> beg, end, mid, nails:', beg, end, mid, totalNails)
let result = checkNailed(A, B, totalNails);
if (result) {
console.log('res')
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
console.log('!res')
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
[[1], [2], [3]]
[[1], [2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3]]
[[1], [2], [3, 3, 3, 3, 3, 3, 3, 3, 3, 2]]
[[1, 2, 1], [2, 3, 10], [3, 1, 2]]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] -> beg, end, mid, nails: 0 5 3 [ 0, 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 ] !res [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] -> beg, end, mid, nails: 3 5 4 [ 0, 0, 0, 0, 1, 1, 2, 3, 3, 3, 4 ] res [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] -> beg, end, mid, nails: 3 4 4 [ 0, 0, 0, 0, 1, 1, 2, 3, 3, 3, 4 ] res
function result: -1
function result: 1
[ 0, 0, 0 ] -> beg, end, mid, nails: 0 12 6 [ 0, 1, 1 ] res [ 0, 0, 0 ] -> beg, end, mid, nails: 0 6 3 [ 0, 1, 1 ] res [ 0, 0, 0 ] -> beg, end, mid, nails: 0 3 2 [ 0, 1, 1 ] res [ 0, 0, 0 ] -> beg, end, mid, nails: 0 2 1 [ 0, 1, 1 ] res [ 0, 0, 0 ] -> beg, end, mid, nails: 0 1 1 [ 0, 1, 1 ] res
function result: 10
[ 0, 0, 0 ] -> beg, end, mid, nails: 0 10 5 [ 0, 0, 0, 1 ] !res [ 0, 0, 0 ] -> beg, end, mid, nails: 5 10 8 [ 0, 0, 0, 1 ] !res [ 0, 0, 0 ] -> beg, end, mid, nails: 8 10 9 [ 0, 0, 0, 1 ] !res [ 0, 0, 0 ] -> beg, end, mid, nails: 9 10 10 [ 0, 0, 1, 1 ] res
function result: 2
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] -> beg, end, mid, nails: 0 3 2 [ 0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2 ] res [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] -> beg, end, mid, nails: 0 2 1 [ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 ] !res [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] -> beg, end, mid, nails: 1 2 2 [ 0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2 ] res
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = totalNailsInitial.slice();
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
console.log('-> beg, end, mid, nails:', beg, end, mid, totalNails)
let result = checkNailed(A, B, totalNails);
if (result) {
console.log('res')
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
console.log('!res')
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = totalNailsInitial.slice();
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
console.log('-> beg, end, mid, nails:', beg, end, mid, totalNails)
let result = checkNailed(A, B, totalNails);
if (result) {
console.log('res')
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
console.log('!res')
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
[[1], [2], [3]]
[[1], [2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3]]
[[1], [2], [3, 3, 3, 3, 3, 3, 3, 3, 3, 2]]
[[1, 2, 1], [2, 3, 10], [3, 1, 2]]
-> beg, end, mid, nails: 0 5 3 [ 0, 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 ] !res -> beg, end, mid, nails: 3 5 4 [ 0, 0, 0, 0, 1, 1, 2, 3, 3, 3, 4 ] res -> beg, end, mid, nails: 3 4 4 [ 0, 0, 0, 0, 1, 1, 2, 3, 3, 3, 4 ] res
function result: -1
function result: 1
-> beg, end, mid, nails: 0 12 6 [ 0, 1, 1 ] res -> beg, end, mid, nails: 0 6 3 [ 0, 1, 1 ] res -> beg, end, mid, nails: 0 3 2 [ 0, 1, 1 ] res -> beg, end, mid, nails: 0 2 1 [ 0, 1, 1 ] res -> beg, end, mid, nails: 0 1 1 [ 0, 1, 1 ] res
function result: 10
-> beg, end, mid, nails: 0 10 5 [ 0, 0, 0, 1 ] !res -> beg, end, mid, nails: 5 10 8 [ 0, 0, 0, 1 ] !res -> beg, end, mid, nails: 8 10 9 [ 0, 0, 0, 1 ] !res -> beg, end, mid, nails: 9 10 10 [ 0, 0, 1, 1 ] res
function result: 2
-> beg, end, mid, nails: 0 3 2 [ 0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2 ] res -> beg, end, mid, nails: 0 2 1 [ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 ] !res -> beg, end, mid, nails: 1 2 2 [ 0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2 ] res
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = totalNailsInitial.slice();
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
console.log('-> beg, end, mid, nails:', beg, end, mid, totalNails)
let result = checkNailed(A, B, totalNails);
if (result) {
console.log('res')
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = totalNailsInitial.slice();
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
// console.log('-> beg, end, mid, nails:', beg, end, mid, totalNails)
let result = checkNailed(A, B, totalNails);
if (result) {
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
[[1], [2], [3]]
[[1], [2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3]]
[[1], [2], [3, 3, 3, 3, 3, 3, 3, 3, 3, 2]]
[[1, 2, 1], [2, 3, 10], [3, 1, 2]]
function result: -1
function result: 1
function result: 10
function result: 2
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = totalNailsInitial.slice();
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
// console.log('-> beg, end, mid, nails:', beg, end, mid, totalNails)
let result = checkNailed(A, B, totalNails);
if (result) {
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = totalNailsInitial.slice();
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
// console.log('-> beg, end, mid, nails:', beg, end, mid, totalNails)
let result = checkNailed(A, B, totalNails);
if (result) {
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = totalNailsInitial.slice();
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
// console.log('-> beg, end, mid, nails:', beg, end, mid, totalNails)
let result = checkNailed(A, B, totalNails);
if (result) {
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
[[1], [2], [3]]
[[1], [2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3]]
[[1], [2], [3, 3, 3, 3, 3, 3, 3, 3, 3, 2]]
[[1, 2, 1], [2, 3, 30000], [3, 1, 2]]
function result: -1
function result: 1
function result: 10
function result: 2
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = totalNailsInitial.slice();
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
// console.log('-> beg, end, mid, nails:', beg, end, mid, totalNails)
let result = checkNailed(A, B, totalNails);
if (result) {
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
[[1], [2], [3]]
[[1], [2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3]]
[[1], [2], [3, 3, 3, 3, 3, 3, 3, 3, 3, 2]]
[[1, 2, 3], [2, 3, 30000], [3, 1, 2]]
function result: -1
function result: 1
function result: 10
function result: 2
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = totalNailsInitial.slice();
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
// console.log('-> beg, end, mid, nails:', beg, end, mid, totalNails)
let result = checkNailed(A, B, totalNails);
if (result) {
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = totalNailsInitial.slice();
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
// console.log('-> beg, end, mid, nails:', beg, end, mid, totalNails)
let result = checkNailed(A, B, totalNails);
if (result) {
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
[[1], [2], [3]]
[[1], [2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3]]
[[1], [2], [3, 3, 3, 3, 3, 3, 3, 3, 3, 2]]
[[1, 2, 4], [2, 3, 30000], [3, 1, 2, 30000]]
function result: -1
function result: 1
function result: 10
function result: 4
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = totalNailsInitial.slice();
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
// console.log('-> beg, end, mid, nails:', beg, end, mid, totalNails)
let result = checkNailed(A, B, totalNails);
if (result) {
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
[[1], [2], [3]]
[[1], [2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3]]
[[1], [2], [3, 3, 3, 3, 3, 3, 3, 3, 3, 2]]
[[1, 2, 4], [2, 3, 30000], [3, 1, 2, 30000]]
function result: -1
function result: 1
function result: 10
function result: 4
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B, C) {
// write your code in JavaScript (Node.js 8.9.4)
let maxB = Math.max(...B);
let beg = 0;
let end = C.length;
let lastPossible = -1;
if (end === 1) {
if(A[0] <= C[0] && B[0] >= C[0]) {
return 1;
} else {
return -1;
}
}
const totalNailsInitial = Array.from({ length: maxB+1}, () => 0);
while (beg <= end) {
let mid = Math.round((beg + end) / 2);
let totalNails = totalNailsInitial.slice();
for (let i = 0; i < mid; i++) {
totalNails[C[i]] = 1;
}
for (let i = 1; i < maxB + 1; i++) {
totalNails[i] += totalNails[i-1];
}
// console.log('-> beg, end, mid, nails:', beg, end, mid, totalNails)
let result = checkNailed(A, B, totalNails);
if (result) {
lastPossible = mid;
if (end === mid) {
break;
}
end = mid;
} else {
beg = mid;
}
}
return lastPossible;
}
function checkNailed(A, B, totalNails) {
for (let i = 0; i < A.length; i++) {
if (totalNails[A[i] - 1] === totalNails[B[i]]) {
return false;
}
}
return true;
}
The solution obtained perfect score.