Skip to content

Instantly share code, notes, and snippets.

View dashsaurabh's full-sized avatar

Saurabh Dashora dashsaurabh

View GitHub Profile
@dashsaurabh
dashsaurabh / singly-linked-list-javascript.js
Last active December 23, 2019 07:37
Singly Linked List Implementation in Javascript
class Node {
constructor(val){
this.val = val;
this.next = null
}
}
class SinglyLinkedList{
constructor(){
this.length = 0;
@dashsaurabh
dashsaurabh / stack-javascript.js
Last active September 5, 2022 03:16
Stack Implementation in Javascript
class Node {
constructor(val){
this.val = val;
this.next = null;
}
}
class Stack {
constructor(){
this.first = null;
@dashsaurabh
dashsaurabh / queue-javascript.js
Created December 25, 2019 05:38
Queue Implementation in Javascript
class Node {
constructor(val) {
this.val = val;
this.next = null
}
}
class Queue {
constructor(){
this.first = null;
@dashsaurabh
dashsaurabh / lru-cache-implementation-javascript.js
Created December 28, 2019 08:59
LRU Cache Implementation Javascript
class Node {
constructor(key, value) {
this.key = key;
this.value = value;
this.next = null;
this.prev = null;
}
}
class LRUCache {
@dashsaurabh
dashsaurabh / min-binary-heap.js
Created December 30, 2019 03:22
Heap Implementation in Javascript
class MinBinaryHeap {
constructor() {
this.values = []
}
insert(val) {
this.values.push(val)
//first element in the heap
@dashsaurabh
dashsaurabh / queue-using-stacks.js
Created December 31, 2019 09:34
Queue Using Stacks
class Queue {
constructor() {
this.pushStack = new Stack();
this.popStack = new Stack();
this.size = 0;
}
enqueue(val) {
this.pushStack.push(val);
this.size = this.pushStack.length + this.popStack.length;
@dashsaurabh
dashsaurabh / merge-sorted-linked-lists.js
Created January 3, 2020 11:49
Merge Two Sorted Linked Lists
class Node {
constructor(val){
this.val = val;
this.next = null
}
}
class SinglyLinkedList{
constructor(){
this.length = 0;
@dashsaurabh
dashsaurabh / min-value-stack.js
Last active January 4, 2020 10:33
Min Value Stack Get in O(1)
class Node {
constructor(val){
this.val = val;
this.next = null;
}
}
class ItemStack {
constructor(){
this.first = null;
@dashsaurabh
dashsaurabh / sort-stack-using-temp-stack.js
Created January 13, 2020 08:11
Sort a Stack using Temp Stack
class Node {
constructor(val) {
this.val = val;
this.next = null;
}
}
class Stack {
constructor() {
@dashsaurabh
dashsaurabh / leet-code-two-sum.js
Created January 18, 2020 10:39
Find the Indices of Two Numbers From an Array Whose Sum is Equal to the Target
/**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
var twoSum = function(nums, target) {
let lookUp = {}
for(let i = 0; i < nums.length; i++) {