JavaScript LIVE Coding Interview Round (Mock)

preview_player
Показать описание
In this video, we have a candidate, a fresher, who tries to solve a live coding problem in a javascript interview

#reactjs #javascript #interview #leetcode

🤯 Crash Courses (Single Video)

🧑‍🏫 Full Course Playlists

💻 Projects Playlists

🕹 Mini Projects (Single Video)

Рекомендации по теме
Комментарии
Автор

Binary search is POSSIBLE here.

We can determine which element should be present at ith index using simpe A.P formula and if correct element present, move right else move left side.

Thanks for this content.

varandeepsahota
Автор

This does work fine!
const inp = [5, 7, 9, 11, 15, 17];
const outp = [];

for(let i=0; i < inp.length; i++){
if(inp[i]+2 != inp[i+1]){
outp.push(inp[i]+2);
}
}

console.log(outp);

addep-kardy
Автор

const input= [5, 7, 9, 11, 15, 17]
input.filter((e, i)=>{return(input[i+1]-input[i])>2})
.map((e)=>e+2)
.filter((e, i)=>i<1) // last filter for only first occurance

karthikhs
Автор

let arr = [5, 7, 9, 11, 15, 17];
let missing = 0;
for (let i = 0; i < arr.length; i++) {
let el = arr[i];
let next_el = arr[i + 1];
if (next_el - el !== 2) {
missing = el + 2;
break;
}
}
console.log(missing);

Its_Abhi_Thakur
Автор

my code works with any case:

const input = [1, 2, 3, 4, 5, 6, 7, 9];
function checkMate(arr) {
let diff = arr[1] - arr[0];
let i = 0;
let j = arr.length-1;
let ans;
while (i < j) {
if(arr[i] + diff === arr[i+1]) {
i++;
} else {
ans = arr[i] + diff;
console.log(ans);
break;
}
}
}
checkMate(input);

YourSecularBro
Автор

It's very helpful... please continue😊

sannisinha
Автор

Map all the values inside array then go for a loop that iterates within the req range then for each odd no check it is present in map or not if not then print and break

itechinnovations
Автор

Hey, @coderdost please do more videos like this...

AbdurRahimKhan-gzjo
Автор

const arr = [5, 7, 9, 11, 13, 15, 17, 21];

let index = 0;
for (let oddNum = arr[0]; oddNum <= arr[arr.length - 1]; oddNum += 2) {
if (arr[index] !== oddNum) {
console.log(oddNum);
break;
}
index++;
}

Rohit-zskn
Автор

in your code for loop should iterate till array.length-1

khanapeena
Автор

Because binary search is applicable where we r given a target number to search in an array .. which is not in this case .

ApurvaKashyap-kjqz
Автор

We can not apply binary search for this problem as we have to evaluate key from the array itself.

sanvijha
Автор

function missOdd(arr){
let first=0, last=arr.length-1, mid = 0, first_element = arr[0];

if(first_element+2*last == arr[last] ) return "no element is missed";

while(first<=last){
mid = Math.floor((first+last)/2);
first = mid+1;
else last = mid-1;
}

return first_element + 2*first;

}

console.log(missOdd([5, 7, 11, 13, 15, 17]));

😀

yesuraju-tfyp
Автор

const input = [5, 7, 9, 11, 15, 19];
for(let i=1;i<input.length;i++){
if(input[i-1]+2 != input[i]){
console.log(input[i-1]+2)
break
}
}

GurpreetSingh-gogsy
Автор

const input = [5, 7, 9, 11, 13, 15, 17, 21];

for (i = 0; i <= input.length; i++) {
let number = input[i];
let oddNumber = input[i + 1];
let margin = oddNumber - number;
if (!(margin === 2))
return console.log(
"This number is missing:",
oddNumber - 2
);
}

MehulJadavIndia
Автор

const arr= [3, 5, 7, 9, 13]
let odd=arr[0];
for(let i=0;i<arr.length;i++){
if(arr[i]!=odd){
console.log (odd);
}
else{
odd+=2
}
}

happylaughy
Автор

I guess using some mathematics can be helpful.
But i would use it only if array was large and we need to solve it in minimum time complexity else i would use sorting approach

1) Find max and min at once from array
2)find sum of odd numbers from 1 to nth term(let x)
3)find total sum of elemnts given in array (let y)
4)find total sum of odd number from min to max that we found above(let z)
5)lastly: (x-y)-(x-z)
This can be simplified but you compolsary need x to find y and z

Please correct if i am wrong.
I just ried my approach

Rubyd
Автор

const input = [1, 5, 7, 9, 11, 15, 17, 21, 25];
let inputFirst = input[0];
let inputEnd = input.at(-1);
let missDigit = [];
for(let i = inputFirst; i<=inputEnd; i++) {
if( i%2 !==0 && !input.includes(i)) {
missDigit.push(i);
}
}

console.log(missDigit);

MrHimanshuji
Автор

let input =[5, 7, 11, 13, 15, 17];
let out = 13
function s(input){
for(let i= 0; i<input.length; i++){
let temp = input[i]
if(temp+2 !== input[i+1])
{
return input[i]+2
}
}
}
// s(input)
console.log(s(input))

AkashSingh-xfbd
Автор

const input = [5, 7, 9, 11, 15, 17];

let missingNum = "";
for(let i= 0 ; i < input.length; i++){

if (input[i] + 2 != input[i+1]){
missingNum = input[i]+2;
break;

}
}
console.log(missingNum)

//output missing odd number is 13

yournanban