This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Input: ["1, 3, 4, 7, 13", "1, 2, 4, 13, 15"] | |
Output: 1,4,13 | |
function FindIntersection(strArr) { | |
// code goes here | |
const [leftSide,rightSide]=strArr | |
const right=rightSide.split(',').map(el=>el.trim()) | |
const left=leftSide.split(',').map(el=>el.trim()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const arr=['one','two','three','four'] | |
const verif=[ | |
{id:'one'}, | |
{id:'aaaa'}, | |
{id:'two'}, | |
{id:'bbbb'}, | |
{id:'three'}, | |
{id:'four'}, | |
] | |
verif.filter((el)=>{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const magic = [ | |
[8, 1, 6, 3, 5, 7, 4, 9, 2], | |
[6, 1, 8, 7, 5, 3, 2, 9, 4], | |
[4, 3, 8, 9, 5, 1, 2, 7, 6], | |
[2, 7, 6, 9, 5, 1, 4, 3, 8], | |
[2, 9, 4, 7, 5, 3, 6, 1, 8], | |
[4, 9, 2, 3, 5, 7, 8, 1, 6], | |
[6, 7, 2, 1, 5, 9, 8, 3, 4], | |
[8, 3, 4, 1, 5, 9, 6, 7, 2], | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const b= 10; | |
const keyboards=[3, 1]; | |
const drives=[5, 2, 8] | |
function getMoneySpent(keyboards, drives, b) { | |
let arr=[]; | |
for(let i=0;i<keyboards.length;i++){ | |
for(let j=0;j<drives.length;j++){ | |
if(keyboards[i]+drives[j]<=b) | |
arr.push(keyboards[i]+drives[j]) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let path = [ | |
'DDUDUDDUDDUDDUUUUDUDDDUUDDUUDDDUUDDUUUUUUDUDDDDUDDUUDUUDUDUUUDUUUUUDDUDDDDUDDUDDDDUUUUDUUDUUDUUDUDDD'] | |
const cat = [1, 2, 3]; | |
const steps = 8; | |
function countingValleys(steps, path) { | |
let count = 0; | |
let val = 0; | |
let distance = steps; | |
const arr = path[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ar = [10, 20, 20, 10, 10, 30, 50, 10, 20]; | |
const n = 9; | |
function sockMerchant(n, ar) { | |
let count = 0; | |
ar.sort((a, b) => a - b); | |
for (let i = 0; i < ar.length; i++) { | |
if (ar[i] === ar[i + 1]) { | |
i++ | |
count++; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const bill = [3, 10, 2, 9]; | |
const k = 1; | |
const b = 12; | |
function bonAppetit(bill, k, b) { | |
const result = bill.reduce((acc, el) => acc + el, 0); | |
if((result-bill[k])/2===b)console.log('bun') | |
else{console.log(b-(result-bill[k])/2)} | |
///////////OR////////////// | |
if (k === 0) { | |
bill.shift(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const arr=[1, 2, 3, 4,5, 4, 3, 2, 1, 3, 4] | |
function migratoryBirds(arr) { | |
let objectArr=arr.reduce((obj, b)=> { | |
obj[b] = ++obj[b] || 1; | |
return obj; | |
}, {}); | |
// console.log(objectArr) | |
const maxVal=Math.max(...Object.values(objectArr)) | |
const num=Object.keys(objectArr).find(key => objectArr[key] === maxVal) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ar = [1, 3, 2, 6, 1, 2]; | |
const n = 6; | |
const k = 3; | |
function divisibleSumPairs(n, k, ar) { | |
let count=0; | |
for(let i= 0;i<n;i++){ | |
for(let j=i+1;j<n;j++){ | |
let sum =ar[i]+ar[j]; | |
if(sum%k===0){ | |
count++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let num = s; | |
let nums = []; | |
let count = 0; | |
const s = [4]; | |
const d = 4; | |
const m = 1; | |
function birthday(s, d, m) { | |
let num = s; | |
let nums = []; |
NewerOlder