View parentheses.js
This file contains 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
/** | |
* question : Given a string s containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]’, | |
* determine if the input string is valid. | |
* An input string is valid if: Open brackets must be | |
* closed by the same type of brackets. Open brackets must be closed in the correct order. | |
*/ | |
let parenthese = "()[]{}" | |
function checkByReplace(s) { | |
while(true) { | |
let len = s.length; |
View selectionSort.js
This file contains 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 arr = [2, 12, -100, -15, -2]; | |
/** | |
* Selection sort is a sorting algorithm that selects the smallest element from an unsorted list in each iteration | |
* and places that element at the beginning of the unsorted list. | |
* @param {*} arr | |
* @returns Array sorted. | |
* Uses: | |
* 1. checking of all the elements is compulsory. | |
* 2. cost of swapping does not matter. |
View bubbleSort.js
This file contains 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 arr = [-2, 45, 0, 11, -9]; | |
/* | |
* Bubble sort is a sorting algorithm that compares two adjacent elements and swaps them until they are in the intended order. | |
*/ | |
function bubbleSort(arr) { | |
// loop to access each array element | |
for (let i = 0; i < arr.length; i++) { | |
// keep track of swapping |
View debounce.js
This file contains 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
/** | |
* use this function if you want to call other function after some | |
* time(provided by you in ms parameter) with latest arguments. | |
* Basically it delay our functino call by given MS(milliseconds). | |
*/ | |
function debounce(fun,ms) { | |
let time; // storing timer returned by setTimeout api. | |
return function() { | |
clearTimeout(time); // clear timer on each time of function call. | |
time = setTimeout(() => fun(...arguments), ms) |
View Queue.js
This file contains 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
/** | |
* A queue can remove only the most recently added value, what if we need to remove old value. here comes another | |
* data structure QUEUE. | |
* queue is work on FIRST IN FIRST OUT | |
* | |
* queue is work on LAST IN FIRST OUT principle. | |
* queue is just like array with only capabilities of push and pop (method). | |
* [6] | |
* [5] | |
* [4] |
View Stack.js
This file contains 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
/** | |
* A stack is useful when we want to add data in sequential order and remove data. Based on its definition, | |
* a stack can remove only the most recently added data. | |
* | |
* stack is work on LAST IN FIRST OUT principle. | |
* stack is just like array with only capabilities of push and pop (method). | |
* [6] ----> which is last element of stack | |
* [5] | |
* [4] | |
* [3] |
View singleLinkedList.js
This file contains 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
/** | |
* linked list is a linear data structure similar to an array. However, unlike arrays, | |
* elements are not stored in a particular memory location or index. Rather each element is a separate | |
* object that contains a pointer or a link to the next object in that list. | |
* for ex: head--> [D, reference to next] [D, reference to next] [D, null] --> tail | |
* D belongs to data. | |
* The head is a reference to the first node in the linked list. | |
* The last node on the list points to null. If a list is empty, the head is a null reference | |
*/ |