This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isInterleave = function(s1, s2, s3) { | |
// caso trivial | |
if (s3.length === 0) { | |
return s1.length === 0 && s2.length === 0 | |
} | |
// caso general | |
let result1 = false, result2 = false | |
if (s1.length > 0 && s3[0] === s1[0]) { | |
result1 = isInterleave(s1.substring(1), s2, s3.substring(1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var kConcatenationMaxSum = function(arr, k) { | |
let maxSum = calculateMaxSubArraySum(arr) | |
if (k === 1) return maxSum | |
let newArr = [...arr, ...arr] | |
let sum = calculateMaxSubArraySum(newArr) | |
if (sum <= maxSum) { | |
return maxSum | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var findLUSlength = function(strs) { | |
strs = strs.sort((a, b) => b.length - a.length) | |
let count = 0 | |
for (let i=strs.length-1; i >= 0; i--) { | |
for (let j=strs.length-1; j >= 0; j--) { | |
if (i !== j) { | |
if (strs[j].includes(strs[i])) { | |
count++ | |
break | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isValidSudoku = function(board) { | |
for (let i=0; i < board.length; i++) { | |
if (!isValidColumn(board, i) || !isValidRow(board, i) || !isValidSubBox(board, i)) { | |
return false | |
} | |
} | |
return true | |
}; | |
function isValidColumn(board, col) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var solve = function(board) { | |
for (let row=0; row < board.length; row++) { | |
// columna izquierda | |
if (board[row][0] === "O") markCells(board, row, 0) | |
// columna derecha | |
const col = board[row].length-1 | |
if (board[row][col] === "O") markCells(board, row, col) | |
} | |
for (let col=0; col < board[0].length; col++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dailyTemperatures = function(temperatures) { | |
const result = [] | |
for (let i=0; i < temperatures.length; i++) { | |
let pos = 0 | |
for (let j=i+1; j < temperatures.length && pos === 0; j++) { | |
if (temperatures[j] > temperatures[i]) pos = j | |
} | |
result.push(pos > 0 ? pos - i : 0) | |
} | |
return result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var numOfArrays = function(n, m, k) { | |
let sum = 0 | |
for (let i=1; i <= m; i++) { | |
sum += i**(n-1) | |
} | |
return sum | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var findingUsersActiveMinutes = function(logs, k) { | |
const users = groupActionsByUser(logs) | |
const uams = groupByActiveMinutes(users) | |
const result = [] | |
for (let i=0; i < k; i++) { | |
result.push(uams[i+1] || 0) | |
} | |
return result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const A = 65 | |
/*var convertToTitle = function(n) { | |
let result = "" | |
while (n > 26) { | |
const mod = (n - 1) % 26 | |
n = Math.floor((n - 1) / 26) | |
result = String.fromCharCode(mod + A) + result | |
} | |
return String.fromCharCode((n - 1) + A) + result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function escape(carpark){ | |
let instructions = [] | |
const floors = carpark.length | |
const cells = carpark[0].length | |
let [posX, posY] = findOurPosition(carpark) | |
while (posX != floors - 1 || posY != cells - 1) { | |
const stairY = findStair(carpark[posX]) | |
const newInstructions = generateInstructions(carpark, posX, posY, stairY) |