Skip to content

Commit

Permalink
Merge pull request #13 from pesto-students/week-7
Browse files Browse the repository at this point in the history
Week 7
  • Loading branch information
bhushanhr26 authored Nov 21, 2022
2 parents 1851142 + 9959277 commit 0b72728
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Week-7/Assignment-1/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const reverseList = head => {
let prev = null;
let next = null;
let current = head
while (current !== null){
next = current.next
current.next = prev
prev = current
current = next
}
return prev
}
console.log(reverseList(1->2->3->4->5->6))
28 changes: 28 additions & 0 deletions Week-7/Assignment-2/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var rotateLinkedList = function (head, k) {
var count = 1;
var last = head;
var now = head;

if (!head || !head.next) return head;

while (last.next) {
last = last.next;
count++;
}

k %= count;

if (k === 0) return head;

while (k < count - 1) {
now = now.next;
k++;
}

last.next = head;
head = now.next;
now.next = null;

return head;
};
console.log(rotateLinkedList([2, 4, 7, 8, 9], 5));
16 changes: 16 additions & 0 deletions Week-7/Assignment-3/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const hasLoop = (head) => {
let set = new Set()
let current = head

while(current){
if(set.has(current)){
return true
}else{
set.add(current)
}

current = current.next
}
return false
};
console.log(hasLoop([1,8,3,4]))
17 changes: 17 additions & 0 deletions Week-7/Assignment-4/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function checkParanthesis(str) {
let brackets = [];
for (let i = 0; i < str.length; i++) {
if (str[i] === "(") {
brackets.push(str[i]);

} else if (str[i] === ")") {
if (brackets[brackets.length - 1] === "(") brackets.pop();
else brackets.push("#");

}

}
return true;
}

console.log(checkParanthesis('{([])}'));
15 changes: 15 additions & 0 deletions Week-7/Assignment-5/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function printNGE(arr, n) {
var next, i, j;
for (i = 0; i < n; i++) {
next = -1;
for (j = i + 1; j < n; j++) {
if (arr[i] < arr[j]) {
next = arr[j];
break;
}
}
console.log(arr[i]/n,next);

}
}
console.log(printNGE([6,8,0,1,3],5))

0 comments on commit 0b72728

Please sign in to comment.