This project implements an efficient kth largest element finder using the quickselect algorithm.
- Node.js
- TypeScript compiler (
tsc)
The only npm dependencies are TypeScript and Node.js type definitions, which are used for development and compilation only. The runtime code uses Node.js built-ins only; you can run the compiled JavaScript directly with Node from the output folder. see sample below
tsc --target ES2020 --module commonjs --outDir output/task1 task1/kthLargest.ts task1/kthLargest.test.ts
node output/task1/kthLargest.test.jsYou can also run:
npm run test:task1- Correctness and edge cases: Input validation throws on empty arrays or invalid
rank, and tests covernums=[],rank=0,rank>n, andnums=[1], rank=1. - Efficiency: Quickselect provides average
$O(n)$ time with$O(1)$ extra space; noArray.sort()is used. - Readability and modularity: Logic is split into
findKthLargestElement,partition,swap, andrandomIntwith JSDoc comments. - Test coverage: 5+ assertions include duplicates, rank=1, rank=n, and invalid inputs.
This task implements an LRU cache with optional per-entry expiration (TTL).
- Node.js
- TypeScript compiler (
tsc)
The only npm dependencies are TypeScript and Node.js type definitions, which are used for development and compilation only. The runtime code uses Node.js built-ins only; you can run the compiled JavaScript directly with Node from the output folder. see sample below
tsc --target ES2020 --module commonjs --outDir output/task2 task2/lruCache.ts task2/lruCache.test.ts
node output/task2/lruCache.test.jsYou can also run:
npm run test:task2- Correct LRU behavior: Tests cover eviction and recency updates.
- Expiration logic: Tests verify TTL expiry and overwrite behavior.
- Robustness: Tests cover capacity=0, negative capacity, and invalid keys.
- Complexity: get/put are
$O(1)$ average with hash map + doubly linked list.