Skip to content

Commit 62ee90a

Browse files
author
Mohan
committed
questions added
1 parent e9170a2 commit 62ee90a

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

PalindromeCreator.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ function PalindromeCreator (str) {
1717
// str minus 1 char:
1818
let temp1 = str.slice(0, i)
1919
let temp2 = str.slice(i + 1)
20-
let removedLetter = str[i]
21-
console.log(removedLetter + '\n' + 'part 1: ' + temp1, '\npart 2: ' + temp2 + '\n')
20+
// let removedLetter = str[i]
21+
// console.log(removedLetter + '\n' + 'part 1: ' + temp1, '\npart 2: ' + temp2 + '\n')
2222
let tempStr = temp1 + temp2
2323

24+
console.log(temp1, temp2, tempStr)
2425
if (isPalindrome(tempStr)) {
2526
return str[i]
2627
}
2728
}
2829
}
2930

30-
PalindromeCreator('abjchba')
31+
console.log(PalindromeCreator('kjjjhjjj'))

subarray.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// input arr = [1, 4, 20, 3, 10, 5]
2+
// value = 33
3+
// result = [3, 5]
4+
5+
// input arr = [1, 2, 3, 4, 5, 0, 0, 0, 0, 6, 7, 8, 9, 10]
6+
// value = 15
7+
// result = [1, 8]
8+
9+
const arr = [1, 4, 20, 3, 10, 5]
10+
const subArray = (arr, value) => {
11+
let sum = 0
12+
let right = 0
13+
let left = 0
14+
let result = [0, 0]
15+
16+
while (right < arr.length) {
17+
sum += arr[right]
18+
while (left < right && sum > value) {
19+
sum -= arr[left++]
20+
}
21+
22+
console.log(result.length, result[1], result[0], right, left)
23+
if (sum === value && (result.length === 1 || ((result[1] - result[0]) < (right - left)))) {
24+
result = [ left + 1, right + 1 ]
25+
}
26+
right++
27+
}
28+
29+
console.log('largest sub array', result)
30+
}
31+
32+
subArray(arr, 33)

0 commit comments

Comments
 (0)