Skip to content

Instantly share code, notes, and snippets.

View blacksheep557's full-sized avatar
🎯
Focusing

Rahul Masih blacksheep557

🎯
Focusing
View GitHub Profile
function uncrossedLines2(upperPanel = [], lowerPanel = [], ptr1 = 0, ptr2 = 0) {
let array = [];
for (let p1 = ptr1; p1 < upperPanel.length; p1++) {
for (let p2 = ptr2; p2 < lowerPanel.length; p2++) {
let sumIfJoined = 0;
let sumIfNotJoined = 0;
if (upperPanel[p1] === lowerPanel[p2]) {
sumIfJoined++;
sumIfJoined += uncrossedLines2(upperPanel, lowerPanel, p1 + 1, p2 + 1);
sumIfNotJoined += uncrossedLines2(upperPanel, lowerPanel, p1, p2 + 1);
function sameLength(inputString = "") {
let lastElement = inputString.charAt(0);
let lastCountStack = [];
let lastCount = 0;
for (let i = 0; i < inputString.length; i++) {
let currentValue = inputString.charAt(i);
if (currentValue === lastElement) {
lastCount++
} else {
lastElement = currentValue;
function stemPlot(inputArray = ['']) {
inputArray = inputArray.map((val) => val.toString().padStart(2, '0'));
let stemsMap = new Map();
for (let i = 0; i < inputArray.length; i++) {
let [stem, leaf] = [inputArray[i].substring(0, inputArray[i].length - 1), inputArray[i].substring(inputArray[i].length - 1)];
let stemFromMap = stemsMap.get(stem);
if (stemFromMap === undefined) {
stemFromMap = [leaf]
} else {
stemFromMap.push(leaf);
function mergeAllLists(list = [{}]) {
if (list.length === 0) return {};
let resultList = {};
let resultPtr = resultList;
let indexToIncrement = Infinity;
let foundSome = true;
while (foundSome) {
let minValue = Infinity;
let found = 0;
foundSome = false;
function findWaterHeight(heights = [1], water = 10) {
let currentWidth = 1;
for (let i = heights.length; i > 1; i--) {
let [last, secondLast] = [heights[i], heights[i - 1]];
let currentAvailableHeight = secondLast - last;
let currentVol = currentWidth * currentAvailableHeight
if (water < currentVol) {
return water;
} else {
water -= currentAvailableHeight - currentWidth;
function unshift(linkedList, studentName) {
return {
value: studentName,
next: linkedList
};
}
class LinkedList {
head;
tail = this.head;
function unshift(linkedList, studentName) {
return {
value: studentName,
next: linkedList
};
}
class LinkedList {
head;
tail = this.head;
function exclusiveTimeFunction(total = 1, logs = ["1"]) {
let resultList = Array(total).fill(0);
let functionsStack = [];
let lastTimeStamp = Number(logs[0].split(':')[2]);
for (let i = 0; i < logs.length; i++) {
let [id, state, time] = [Number(logs[i].split(':')[0]), logs[i].split(':')[1], Number(logs[i].split(':')[2])];
let diff = time - lastTimeStamp;
lastTimeStamp = time;
if (functionsStack.length !== 0) {
let currentFunction = functionsStack[functionsStack.length - 1];
function getCharMatrix(msg,keyword){
let matrix = [];
let row = [];
for (let i = 0; i < msg.length; i++) {
row.push(msg.charAt(i));
if (row.length === keyword.length) {
matrix.push(row);
row = [];
}
}
function fillShelf(books = [[1]], width = 1) {
let toReturnHeight = 0;
let currentMaxHeight = 0;
let currentWidth = 0;
for (let i = 0; i < books.length; i++) {
let [width1, height] = books[i];
if (currentWidth + width1 > width) {
toReturnHeight += currentMaxHeight;
currentMaxHeight = 0;
currentMaxHeight = height;