Skip to content

Instantly share code, notes, and snippets.

View Preetiraj3697's full-sized avatar
🎯
Focusing

Preeti Raj Preetiraj3697

🎯
Focusing
View GitHub Profile
@Preetiraj3697
Preetiraj3697 / SparseArray.js
Created October 21, 2022 05:51 — forked from rahul4coding/SparseArray.js
Sparse Arrays Hackerrank Solution by Rahul Bhatija
// https://www.hackerrank.com/challenges/sparse-arrays
// Simple JavaScript solution
function matchingStrings(strings, queries) {
return queries.map(x=>strings.filter(y=>y===x).length)
}
@Preetiraj3697
Preetiraj3697 / insertNodeAtTail.js
Created October 21, 2022 05:51 — forked from rahul4coding/insertNodeAtTail.js
Insert node at a tail of Linked List | HAckerRank
// 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{
@Preetiraj3697
Preetiraj3697 / insertNodeAtPosition.js
Created October 21, 2022 05:50 — forked from rahul4coding/insertNodeAtPosition.js
Insert node at specified position in a Linked List | JS
function insertNodeAtPosition(head, data, position) {
var trackedNode = head;
var newNode = new SinglyLinkedListNode(data);
if(head==null){
head = newNode
return head;
}
@Preetiraj3697
Preetiraj3697 / deleteNode.js
Last active October 21, 2022 05:48 — forked from rahul4coding/deleteNode.js
Delete node in a Linked List from a specified position
const LinkedListNode = class {
constructor(nodeData) {
this.data = nodeData;
this.next = null;
}
};
// Complete the function below
@Preetiraj3697
Preetiraj3697 / reversePrint.js
Last active October 21, 2022 05:46 — forked from rahul4coding/reversePrint.js
Reverse Print a given linkedList | JS
const LinkedListNode = class {
constructor(nodeData) {
this.data = nodeData;
this.next = null;
}
}
// Complete the function below
@Preetiraj3697
Preetiraj3697 / CompareLists.js
Created October 21, 2022 05:43 — forked from rahul4coding/CompareLists.js
Comparing Two Linked Lists | JS
function CompareLists(a, b) {
while(a!==null && b!==null){
if(a.data !== b.data){
return 0
}else{
a=a.next;
b=b.next;
}
@Preetiraj3697
Preetiraj3697 / mergeLists.js
Created October 21, 2022 05:42 — forked from rahul4coding/mergeLists.js
merge two sorted Linked list
function mergeLists(head1, head2) {
var result = new SinglyLinkedListNode();
// case1
if(head1==null){
return head2;
}else if(head2==null){
return head1;
}
@Preetiraj3697
Preetiraj3697 / getNode.js
Created October 21, 2022 05:41 — forked from rahul4coding/getNode.js
Get node value in a linked list position from tail | JS
function getNode(head, positionFromTail) {
var length =0;
var tp = head;
while(tp!==null){
length++;
tp=tp.next
}
let currentPosition=0;
if(head==null){
@Preetiraj3697
Preetiraj3697 / findMergeNode.js
Created October 21, 2022 05:39 — forked from rahul4coding/findMergeNode.js
Find merge point of two linked list | JS
function findMergeNode(headA, headB) {
let currentA = headA;
let currentB = headB;
while(currentA!==currentB){
//headA
if(currentA.next==null){
currentA.next=headB
}else{