Skip to content

Commit d486ede

Browse files
committed
updates
1 parent 6072dcd commit d486ede

File tree

1 file changed

+52
-19
lines changed

1 file changed

+52
-19
lines changed

RandomPractise/server.js

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,32 +1136,65 @@ const createServer = http.createServer()
11361136

11371137
// ==================== First Overlapping Array =======
11381138

1139-
function OverlappingArray(array){
1139+
// function OverlappingArray(array){
11401140

1141-
let sort = array.sort((a,b)=> a[0]-b[0])
1142-
let output = []
1143-
output.push(array[0])
1141+
// let sort = array.sort((a,b)=> a[0]-b[0])
1142+
// let output = []
1143+
// output.push(array[0])
11441144

1145-
for(let i=1;i<array.length;i++){
1146-
if(output[output.length -1][1] >= array[i][0]){
1147-
output[output.length -1]= [output[output.length -1][0], Math.max(output[output.length -1][1], array[i][1],)]
1145+
// for(let i=1;i<array.length;i++){
1146+
// if(output[output.length -1][1] >= array[i][0]){
1147+
// output[output.length -1]= [output[output.length -1][0], Math.max(output[output.length -1][1], array[i][1],)]
11481148

1149-
}else{
1150-
output.push(array[i])
1149+
// }else{
1150+
// output.push(array[i])
1151+
// }
1152+
// }
1153+
// console.log(output)
1154+
// }
1155+
1156+
// OverlappingArray([[1, 2],[3, 5],[4, 7],[6, 8],[9, 10]])
1157+
1158+
1159+
1160+
function FourNumberSum(incoming, target){
1161+
1162+
let array = incoming.sort((a,b)=> a-b)
1163+
1164+
let mySet = new Set()
1165+
let left =0;
1166+
let right =0;
1167+
let sum =0;
1168+
let result = []
1169+
1170+
for(let i=0;i<array.length -1;i++){
1171+
for(j=i+1;j<array.length-1;j++){
1172+
left = j+1;
1173+
right = array.length -1
1174+
while(left<right){
1175+
sum = array[i]+array[j]+array[left]+array[right]
1176+
if(sum === target){
1177+
let quad = [array[i], array[j], array[left],array[right]]
1178+
mySet.add(quad)
1179+
left++
1180+
}
1181+
else if(sum < target){
1182+
left++
1183+
}
1184+
else if(sum > target){
1185+
right--
1186+
}
1187+
}
11511188
}
11521189
}
1153-
console.log(output)
1190+
mySet.forEach(element => {
1191+
result.push(element)
1192+
})
1193+
return result
11541194
}
11551195

1156-
OverlappingArray([[1, 2],[3, 5],[4, 7],[6, 8],[9, 10]])
1157-
1158-
1159-
1160-
1161-
1162-
1163-
1164-
1196+
const result = FourNumberSum([7, 6, 4, -1, 1, 2], 16)
1197+
console.log(result)
11651198

11661199

11671200
createServer.listen(PORT, () => `Listening to the Port ${PORT}`)

0 commit comments

Comments
 (0)