Skip to content

Commit a24341f

Browse files
committed
final commit
1 parent 12153b7 commit a24341f

10 files changed

+142
-1
lines changed

tuts/warmup-questions/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
## Very easy questions one should be familiar with or practice before proceeding on to the harder ones
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
1.Given a graph, had to compute a list of how many cities
2+
where at a hop distance away from a specific node
3+
4+
2. Given a collection (matrix) of pixels you must find the size of the largest shape.
5+
6+
3. Given a string representing taken seats on a plane and a number N representing the rows on a plane, return the amount of seating arrangements for a family of 3. Seating between isles is not a possible arrangement.
7+
The seating columns are as follows: ABC | DEFG | HJK.
8+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const firstNonRepeatingCharacterConstantSpace = string => {
2+
for (let index = 0; index < string.length; index++) {
3+
if (string.lastIndexOf(string[index]) === index) {
4+
return string[index];
5+
}
6+
}
7+
};
8+
9+
const firstNonRepeatingCharacterLinearTime = string => {
10+
const freqCount = string.split("").reduce((freqCount, character) => {
11+
const count = freqCount[character] || 0;
12+
freqCount[character] = count + 1;
13+
return freqCount;
14+
}, {});
15+
16+
for (let index = 0; index < string.length; index++) {
17+
if (freqCount[string[index]] === 1) {
18+
return string[index];
19+
}
20+
}
21+
};
22+
console.log(
23+
firstNonRepeatingCharacterLinearTime(
24+
"the quick brown fox jumps then quickly blow air"
25+
)
26+
);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const largestPairSum = array => {
2+
if (array.length < 2) {
3+
return -1;
4+
}
5+
let [largest, secondLargest] = [
6+
Math.max(array[0], array[1]),
7+
Math.min(array[0], array[1])
8+
];
9+
for (let i = 2; i < array.length; i++) {
10+
const element = array[i];
11+
if (element > element) {
12+
const temp = largest;
13+
largest = element;
14+
secondLargest = temp;
15+
} else if (element > secondLargest) {
16+
secondLargest = element;
17+
}
18+
}
19+
20+
return largest + secondLargest;
21+
};
22+
23+
const array = [4, 9, 14, 2, 7, 6];
24+
25+
console.log(largestPairSum(array));

tuts/warmup-questions/merge-sorted.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const mergeSortedArrays = (A, B) => {
2+
let i = 0,
3+
j = 0;
4+
const result = [];
5+
while (A[i] || B[j]) {
6+
if (A[i] !== undefined) {
7+
result.push(B[j++]);
8+
}
9+
if (B[j] !== undefined) {
10+
result.push(A[i++]);
11+
}
12+
if (A[i] < B[j]) {
13+
result.push(A[i++]);
14+
}
15+
if (B[j] < A[i]) {
16+
result.push(B[j++]);
17+
} else {
18+
result.push(A[i++]);
19+
result.push(B[j++]);
20+
}
21+
}
22+
return result;
23+
};
24+
console.log(mergeSortedArrays([2, 5, 6, 9], [1, 2, 3, 29]));
Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,28 @@
1-
const removeDuplicatesUno
1+
const removeDuplicatesUnorted = array => {
2+
//
3+
const map = array.reduce((map, element) => {
4+
if (!map[element]) {
5+
map[element] = true;
6+
}
7+
return map;
8+
}, {});
9+
10+
return Object.keys(map).map(element => parseInt(element));
11+
};
12+
13+
const removeDuplicatesSorted = array => {
14+
let lagger = 1;
15+
for (let i = 1; i < array.length - 1; i++) {
16+
while (array[i] === array[i - 1]) {
17+
i++;
18+
}
19+
array[lagger++] = array[i];
20+
}
21+
array.length = lagger;
22+
};
23+
24+
// const array = [1, 2, 1, 1, 4, 6];
25+
// console.log(removeDuplicatesUnorted(array));
26+
const array = [1, 1, 1, 3, 3, 4, 4, 5, 6, 6];
27+
removeDuplicatesSorted(array);
28+
console.log(array);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const removeDuplicateChar = string => {
2+
const map = string.split("").reduce((map, character) => {
3+
map[character] = true;
4+
return map;
5+
}, {});
6+
7+
return Object.keys(map).join("");
8+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const reverseWordsInPlace = sentence => {
2+
return sentence
3+
.split(" ")
4+
.map(word =>
5+
word
6+
.split("")
7+
.reverse()
8+
.join("")
9+
)
10+
.join(" ");
11+
};
12+
13+
console.log(reverseWordsInPlace("What are you doing"));
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const reverse = sentence => {
2+
return sentence.split(" ").reverse();
3+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const swap = (a, b) => {
2+
a = a ^ b;
3+
b = a ^ b;
4+
a = a ^ b;
5+
return [b, a];
6+
};

0 commit comments

Comments
 (0)