sss2kit
v1.1.1
Published
Simple search, sorting, two-pointer and sliding window algorithms
Maintainers
Readme
sss2kit
sss2kit (Search, Sort, Sliding Window, 2 Pointer) is a high-performance, lightweight algorithm library for Node.js, designed for technical interviews, competitive programming, and efficient data processing.
Features
- Lightweight: Zero dependencies and minimal installation size.
- Performant: Optimized implementations of classic data structures and algorithms.
- TypeScript Support: Full type definitions included for enhanced development experience.
- Reliable: Includes a comprehensive unit test suite.
- Modern: ES Module (ESM) first design.
Installation
npm install sss2kitQuick Start
import { quickSort, binarySearch, quickSelect } from "sss2kit";
// Efficiently sort arrays
const sorted = quickSort([5, 3, 1, 4, 2]); // [1, 2, 3, 4, 5]
// Binary search on sorted arrays
const index = binarySearch(sorted, 3); // 2
// Find the k-th smallest element in O(n) average time
const thirdSmallest = quickSelect([3, 2, 1, 5, 4], 2); // 3API Reference
Searching
linearSearch(arr, target)binarySearch(arr, target)lowerBound(arr, target)upperBound(arr, target)firstOccurrence(arr, target)lastOccurrence(arr, target)searchInsertPosition(arr, target)findPeakElement(arr)
Sorting
bubbleSort(arr)selectionSort(arr)insertionSort(arr)mergeSort(arr)quickSort(arr)heapSort(arr)shellSort(arr)countingSort(arr)radixSort(arr)bucketSort(arr)
Two Pointers and Array Utilities
mergeSortedArrays(arr1, arr2)intersectionSorted(arr1, arr2)twoSumSorted(arr, target)removeDuplicatesSorted(arr)moveZeroes(arr)reverseArray(arr, left, right)rotateArray(arr, k)shuffle(arr)- Fisher-Yates shuffleisSorted(arr)- Sort order verification
Selection
quickSelect(arr, k)- Find the k-th smallest element
Sliding Window and Subarray
maxSubarraySum(arr)- Kadane's algorithmmaxSlidingWindowSum(arr, k)minSubarrayLength(target, arr)longestUniqueSubstring(str)fixedWindowAverage(arr, k)
License
ISC © Anusha B
