Skip to content

Instantly share code, notes, and snippets.

View apsicle's full-sized avatar
💭
chillin

Ryan Yan apsicle

💭
chillin
  • Gamechanger
  • New York, New York
View GitHub Profile
// Rewrote my solution from scratch to be more modular
/* Datto is working on creating a backup-time estimator. For simplicity's sake, let's assume that there is only one server completing multiple jobs (i.e. backups) in parallel. Without any parallelization, the ith job takes backupDurationi units of time to be backed up. But if there are n jobs running in parallel, the backup process goes n times slower for each job.
For the ith job you know the value of backupDurationi and the moment startTimesi it was added to the backup queue. Your task is to estimate all the backup completion times. Note that it is impossible to have more than maxThreads threads performing backups in parallel. If there is more than one job waiting to be backed up, the one with the smallest initial backup time is chosen. It's guaranteed that all the jobs are added to the backup queue at different times.
Example
For startTimes = [461620201, 461620202, 461620203],
backupDuration = [2, 2, 2] and maxThreads = 2,
the output should be
function nQueens(n) {
const placeNQueens = (n) => {
let allPermutations = [];
let board = Array(n).fill(Array(n).fill(1));
let permutation = [];
const placeQueen = (board, row, col) => {
const n = board[0].length;
let newBoard = board.map((row) => {
return row.slice();