Table of Contents generated with DocToc
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
// https://www.hackerrank.com/challenges/sparse-arrays | |
// Simple JavaScript solution | |
function matchingStrings(strings, queries) { | |
return queries.map(x=>strings.filter(y=>y===x).length) | |
} |
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
// https://www.hackerrank.com/challenges/insert-a-node-at-the-tail-of-a-linked-list/problem | |
function insertNodeAtTail(head, data) { | |
var newNode = new SinglyLinkedListNode(data); | |
if(head===null){ | |
head = newNode; | |
return head; | |
}else{ |
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 insertNodeAtPosition(head, data, position) { | |
var trackedNode = head; | |
var newNode = new SinglyLinkedListNode(data); | |
if(head==null){ | |
head = newNode | |
return head; | |
} |
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 LinkedListNode = class { | |
constructor(nodeData) { | |
this.data = nodeData; | |
this.next = null; | |
} | |
}; | |
// Complete the function below |
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 LinkedListNode = class { | |
constructor(nodeData) { | |
this.data = nodeData; | |
this.next = null; | |
} | |
} | |
// Complete the function below |
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 CompareLists(a, b) { | |
while(a!==null && b!==null){ | |
if(a.data !== b.data){ | |
return 0 | |
}else{ | |
a=a.next; | |
b=b.next; | |
} |
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 mergeLists(head1, head2) { | |
var result = new SinglyLinkedListNode(); | |
// case1 | |
if(head1==null){ | |
return head2; | |
}else if(head2==null){ | |
return head1; | |
} |
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 getNode(head, positionFromTail) { | |
var length =0; | |
var tp = head; | |
while(tp!==null){ | |
length++; | |
tp=tp.next | |
} | |
let currentPosition=0; | |
if(head==null){ |
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 findMergeNode(headA, headB) { | |
let currentA = headA; | |
let currentB = headB; | |
while(currentA!==currentB){ | |
//headA | |
if(currentA.next==null){ | |
currentA.next=headB | |
}else{ |