-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { equal } = require('assert'); | ||
|
||
function decryptPassword(s) { | ||
// return numbers t right positions | ||
// console.log(s.slice(-10, -1)); | ||
const numPattern = /^\d*/; | ||
|
||
let numbers = numPattern.exec(s)[0]; | ||
s = s.replace(numPattern, ''); | ||
|
||
for (let i = numbers.length - 1; i >= 0; i--) { | ||
if (/\D0/.test(s)) { | ||
s = s.replace('0', numbers[i]); | ||
} else { | ||
break; | ||
} | ||
} | ||
s = s.replace(/([A-Z])([a-z])\*/g, '$2$1'); | ||
return s; | ||
} | ||
|
||
equal(decryptPassword('43Ah*ck0rr0nk'), 'hAck3rr4nk'); | ||
equal(decryptPassword('51Pa*0Lp*0e'), 'aP1pL5e'); | ||
equal(decryptPassword('pTo*Ta*O'), 'poTaTO'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const { equal } = require('assert'); | ||
const { O_DIRECT } = require('constants'); | ||
|
||
function filledOrders(orders, k) { | ||
orders.sort((a, b) => a - b); | ||
let count = 0; | ||
for (let order of orders) { | ||
if (k - order >= 0) { | ||
k -= order; | ||
count++; | ||
} else { | ||
break; | ||
} | ||
} | ||
return count; | ||
} | ||
|
||
equal(filledOrders([10, 30], 40), 2); | ||
equal(filledOrders([5, 4, 6], 3), 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const assert = require('assert'); | ||
|
||
function longestSubarray(arr) { | ||
let i = 0; | ||
let max = 1; | ||
let maxFirstSeen = 0; | ||
function consume() { | ||
let count = 1; | ||
const startIndex = i; | ||
let min = Math.min(arr[i], arr[i + 1]); | ||
while (arr[i + 1] && Math.max(arr[i], arr[i + 1]) - min < 2) { | ||
if (arr[i] !== arr[i + 1]) { | ||
maxFirstSeen = i + 1; | ||
} | ||
count++; | ||
i++; | ||
} | ||
// TODO: get to use maxFirstSeen | ||
max = Math.max(max, count); | ||
} | ||
while (i < arr.length) { | ||
consume(); | ||
} | ||
return max; | ||
} | ||
|
||
assert.deepStrictEqual(longestSubarray([0, 1, 2, 1, 2, 3]), 4); | ||
assert.deepStrictEqual(longestSubarray([1, 1, 1, 3, 3, 2, 2]), 4); | ||
// assert.deepStrictEqual(longestSubarray([1, 1, 1, 2, 2, 3, 3, 2, 2]), 6); |