build(build system or external dependencies changes)
ci(CI configurations and scripts changes)
docs(documentation)
feat(feature)
fix(bug fix)
perf(improves performance)
refactor(restructuring existing code, but not bug or feature)
revert(reverts a previous commit)
style(formatting, missing semi colons, etc.)
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 longestWord = (str: string): void => { | |
if (str?.length === 0) return; | |
const words: string[] = str.split(" "); | |
const longest: string = words.reduce( | |
(a, b) => (b.length > a.length ? b : a), | |
"", | |
); | |
console.log(longest.length, longest); | |
}; |
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 whatFlavors(cost, targetAmount) { | |
const priceToIndexMap = new Map(); | |
for (const [currentIndex, currentPrice] of cost.entries()) { | |
const neededPrice = targetAmount - currentPrice; | |
const displayIndex = currentIndex + 1; | |
if (priceToIndexMap.has(neededPrice)) { | |
const firstFlavorIndex = priceToIndexMap.get(neededPrice); | |
console.log(`${firstFlavorIndex} ${displayIndex}`); | |
return; | |
} |
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 checkMagazine(magazine, note) { | |
// Create a frequency map of words available in the magazine | |
const availableWords = new Map(); | |
for (const word of magazine) { | |
const currentCount = availableWords.get(word) ?? 0; | |
availableWords.set(word, currentCount + 1); | |
} | |
// Check if we can form the note using available words | |
for (const requiredWord of note) { | |
const remainingCount = availableWords.get(requiredWord) ?? 0; |
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 quickSort(arr) { | |
if (arr.length === 0) return []; | |
const pivot = arr[0]; | |
const left = arr.filter((num, i) => i !== 0 && num < pivot); | |
const equal = arr.filter(num => num === pivot); | |
const right = arr.filter((num, i) => i !== 0 && num > pivot); | |
return [...left, ...equal, ...right]; | |
} |
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 bigSorting(unsorted) { | |
return unsorted.sort((a,b) => { | |
const bigA = BigInt(a); | |
const bigB = BigInt(b); | |
if (bigA < bigB) return -1; | |
if (bigA > bigB) return 1; | |
return 0; | |
}); | |
} |
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 checkLevelOrderBST(levelOrder) { | |
if (levelOrder.length === 0) return true; | |
let i = 0; | |
const n = levelOrder.length; | |
// Stack to store nodes with their min and max constraints | |
const stack = []; | |
stack.push({ | |
data: levelOrder[0], | |
min: -Infinity, | |
max: Infinity, |
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
class Node { | |
constructor(data) { | |
this.data = data; | |
this.left = null; | |
this.right = null; | |
} | |
} | |
function insert(root, data) { | |
if (root === null) { | |
return new Node(data); |
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 bfs(n, m, edges, s) { | |
// Create adjacency list for the graph | |
const adjList = new Array(n + 1).fill().map(() => []); | |
// Build the graph from edges | |
for (const [u, v] of edges) { | |
adjList[u].push(v); | |
adjList[v].push(u); // Undirected graph | |
} | |
// Initialize distances array with -1 (unreachable) | |
const distances = new Array(n + 1).fill(-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
function diagonalDifference(arr) { | |
let left = 0; | |
let right = 0; | |
const n = arr.length; | |
for (let i = 0; i < n; i++) { | |
left += arr[i][i]; | |
right += arr[i][n - i - 1]; | |
} | |
return Math.abs(left - right); | |
} |
NewerOlder