JavaScript LIVE Coding Interview Round (Mock)
HTML-код
- Опубликовано: 11 сен 2024
- In this video, we have a candidate, who tries to solve a live coding problem in a javascript interview.
#reactjs #javascript #interview #leetcode
🤯 Crash Courses (Single Video)
Git/Github Crash Course : bit.ly/3JSA5VT
TypeScript Crash Course : bit.ly/372dZSh
Angular Crash Course : bit.ly/3DoGJR1
Vue JS Crash Course : bit.ly/3uDujRl
Python Crash Course : bit.ly/3Dod7U2
React Router Crash Course : bit.ly/36YfO2i
🧑🏫 Full Course Playlists
HTML : bit.ly/36IMq0h
CSS : bit.ly/3LpRQw6
JavaScript : bit.ly/3u049tf
BootStrap : bit.ly/3NA9nDJ
ES 6 : bit.ly/3DvYCh6
DOM Playlist : bit.ly/35nMKB7
ReactJS (Redux & Hooks) : bit.ly/3iMethN
React with TypeScript : bit.ly/3fQjXtF
React Hooks: bit.ly/3Vmh7wV
Redux: bit.ly/3yAIIkl
NodeJS/ExpressJS : bit.ly/35nN6Yt
MongoDB / Mongoose : bit.ly/3qPj0EO
💻 Projects Playlists
MERN Stack Complete Ecommerce : bit.ly/3ymSs0E
Web Design HTML+CSS - Home Page : bit.ly/35nZiIB
Web Design BootStrap - E-Commerce Site : bit.ly/3iPhaz7
React/Redux/Firebase - Todo-App : bit.ly/3DnekL8
🕹 Mini Projects (Single Video)
React - Tic Tac Toe (Redux / Hooks) : bit.ly/3uzLEuy
React - Game of Flag Quiz (Hooks) : bit.ly/3LpTC0e
React - Google Translate Clone (Hooks) : bit.ly/3Lo9xvZ
React - Chat App using Firebase (Hooks) : bit.ly/3wLgymj
Visit our site: coderdost.com
🔴 Full Courses List : coderdost.com/...
🔴 Full Projects List : coderdost.com/...
💾 Source Codes at : github.com/cod...
const input =[2,7,11,4,-2]
let output = [20,15,11,18,24]
let sum = input.reduce((a,b)=>a+b)
let totalsum = []
for (const value of input) {
totalsum.push(sum-value)
}
console.log(totalsum);
Nice approach man
Am also get confused this is good
bdia bhai 👌
let arr = [2, 7, 11, 4, -2];
let output = [];
for (let i = 0; i < arr.length; i++) {
let sum = 0;
for (let j = 0; j < arr.length; j++) {
if (j == i) {
continue;
} else {
sum += arr[j];
}
}
output.push(sum);
}
console.log(output);
let input = [2,7,11,4,-2];
let sum = 0;
for(let ele of input)
sum+=ele;
let output = new Array();
for(let x of input)
{
let z = sum - x;
output.push(z);
}
console.log(output);
O(n) Time
This is o(n2) time complexity. This can be done in o(2n)==o(n)
I have just tried to make the code more Efficient, hope it helps :
const sum = input.reduce((a,b) => {
return (a+b)
})
const result = input.map(item => sum-item)
console.log(result)
don't use caht gpt
@@roshankalamkar7752 first take sum of all no then in new array sum-old array value
const input = [2, 7, 11, 4, -2];
const sum = input.reduce((a, b) => a + b, 0);
const output = input.map((e) => sum - e);
console.log(output);
const input = [2,7,11,4,-2];
const output = [];
for(let i=0; i
just compare u===i not input[u] === input[i] as this will skip the addition of same number
Please give some question everyday ! This helps me to build my confidence ! Believe me solve karne ke bad hi puri video dekhta hu ! Mene kiss approche se kia or sammne kaise kr raha hai
const input = [2,7,11,4,-2]
let arr=[0,0,0,0,0];
arr[0] = input[0];
for(let i=1; i{
return acc+curr;
},0)
for(let i=0; i
3 line code including console.log and input
const arr = [2,7,11,4,-2];
const sum = arr.reduce((a,b) => a+b);
console.log( arr.map( I => sum-i ));
Not that complicated straight forward logic
const input = [2, 7, 11, 4, -2];
const output = [];
for (let i = 0; i < input.length; i++) {
let sum = 0;
for (let j = 0; j < input.length; j++) {
if (j === i) continue;
sum += input[j];
}
output.push(sum);
}
console.log(output);
But time complexity may be O(n^2) ,
We can write two loop diff first for finding sum and then for the sum - input [i]
let netsum = inputSum.reduce((acc,curr)=>{
return acc+curr;
},0);
let output = inputSum.map((val,index,arr)=>{
return netsum-val;
});
console.log(output);
const input=[2,7,11,4,-2];
const output=[20,15,11,18,24]
const sum=0;
newArr=input.map((item)=>input.reduce((acc,i)=>acc+i,sum));
let resArr=[];
for (let i in input){
resArr.push(newArr[i]-input[i])
}
console.log(resArr);
let arr = [2,7,11,4,-2]
let total = 0
let totalArr = []
for(let i=0; i
I think this is enough!!
console.log(input.map(num => input.reduce((sum, num) => sum + num) - num))
edited: it's better to use reduce only once and save the value for later, instead of calculating for every map element
let sum = input.reduce((sum, num) => sum + num)
console.log(input.map(num => sum - num))
It's time complexity is way too much as reduce function will run n times. N2 time complexity.
@@khageshbansal2400 sir! Please read the full comment..xD
@@OctTEN_1010 well played 👏
const arr = [2, 7, 11, 4, -2];
let sum = 0;
let newArr = []
function output() {
for (let i = 0; i < arr.length; i++) {
sum += arr[i]
}
const value = sum;
console.log(value);
for (let i = 0; i < arr.length; i++) {
let num = value - arr[i];
console.log(num);
newArr.push(num)
}
return newArr
}
const a = output();
console.log(a);
let a = [2, 7, 11, 4, -2];
let out = [20, 15, 11, 18, 24];
let b = [];
for (let i = 0; i < a.length; i++) {
b.push(
a.reduce((a, b) => {
return a + b;
}, 0) - a[i]
);
}
console.log(b);
Simplest code just tooked me 10mins to solve, this guy is hilarious 🤣🤣😂😂
const input = [2, 7, 11, 4, -2];
const output = input.map((el, i, arr) => {
const sumableElms = arr.map((elm, ind) => {
return i === ind ? 0 : elm;
});
let sum = 0;
sumableElms.map((elm) => {
return (sum += elm);
});
return sum;
});
console.log("Output : ", output);
@Coder Dost i think this is full fill the requirement
let arr =[2,3,4,5]
function sn(arr){
let result = [];
for(let i =0;i< arr.length;i++){
let sum = 0;
for(j=0;j< arr.length;j++){
if(i===j){
continue;}
else{
let temp = arr[j];
sum += temp
}
}
result.push(sum)
}
return result
}
console.log(sn(arr))
Thanks
++++++++++++++++++++++++++++++++++++++
let arr =[2,3,4,5]
function sn(arr){
let result = [];
for(let i =0;i< arr.length;i++){
let sum = 0;
for(j=0;j< arr.length;j++){
let temp = arr[j];
sum += temp
}
sum -= arr[i]
result.push(sum)
}
return result
}
console.log(sn(arr))
const input = [2, 7, 11, 4, -2]
let sum = input.reduce((a, b)=>a+b)
for(let i =0; i sum -item)
}
console.log(output)
let arr = [2, 7, 11, 4, -2];
let arr1 = [];
const result = arr.reduce((pre, curr) => {
return pre + curr;
},0);
for(let val of arr){
let itemval=result-val;
arr1.push(itemval);
}
console.log(arr1);
This work for me.
input=[2,7,11,4,-2];
output=[ ];
let sum = input.reduce((acc,cur)=>acc+cur);
for(let i=0;i
const number = [2, 7, 11, 4, -2];
const array = []
for(let i=0; i acc + cur);
array.push(total - number[i]);
}
Too simple.
Step 1. Calculate sum of the whole array. In case [2,7,11,4,-2].
Sum is = 22.
Step 2: Map through the input array and subtract the each element on by by with the Sum.
Example:
let output = input.map((value)=>{
return (Sum - value)})
output [20,15,11,24]
Time complexity O(n)
Auxilary space O(n) =>output array
Good
Nice thanks for sharing
Please keep making such videos like these
const input=[2,5,6,9,4,-2];
let output=[];
for(var i=0;ival+acc)
output.push(out-input[i]);
}
console.log(output);
const input = [2,7,11,4,-2]
const sum = input.reduce((total, curr) => total + curr)
const output = input.map(num => sum - num)
console.log(output)
function func(input) {
const newArray = [];
const sum = input.reduce((acc, cur) => {
return acc + cur;
}, 0);
for (let i = 0; i < input.length; i++) {
const item = sum - input[i];
newArray.push(item);
}
return newArray;
}
const input = [2, 7, 11, 4, -2];
const output = func(input);
console.log(output);
Add more interview machine coding rounds. Good content 👍
Hello sir , i have a question
If i am going to give interview for javascript
If he/she ask me DSA
So, can i do the DSA problem in c++ language ?
generally they ask only the psuedo code or white board logic and implementation. but if they ask to implement code. any well-konwn language is generally accepted - C++. Java. Python or JavaScript.
const input = [2, 7, 11, 4, -2]
const output = [20, 15, 11, 18, 24]
let sum = 0;
let result = []
let currIndex = 0
for (let i=0; i {
if(input.indexOf(num) !== i){
return num
}
}).reduce((acc, curr) => {
acc = acc + curr;
return acc
}, 0)
result.push(sum)
}
console.log(result);
const input = [2,7,11,4,-2];
//const output = [20,15,11,18,24];
function sumOfAll(arr){
const output = [];
for(let i = 0;i index !== i).reduce((acc,cur)=>acc+cur,0);
output.push(tempOutput);
}
return output;
}
console.log(sumOfAll(input));
I have solved this from just after know the question didn't watch the full length of the video but once I dragged the video in last Sir suggested the same what I done here
Very Helpful 😊
let arr = [2,7,11,4,-2]
let ans =[];
let sum = arr.reduce((a,b)=>a+b,0);
arr.forEach((elm)=>{
ans.push(sum-elm);
})
console.log(ans);
// the most basic way to do without map and reduce
let arr = [2,7,11,4,-2];
let sumArr = [];
for(let i=0;i
function CheckArr(arr) {
// Method 1
let res1 = [];
for (let i = 0; i < arr.length; i++) {
let left = arr.slice(0, i);
let right = arr.slice(i + 1, arr.length);
let temp = [...left, ...right].reduce((a, b) => a + b, 0);
res1.push(temp);
}
// Method 2
let res = []
for (let i = 0; i < arr.length; i++) {
let temp = 0
for (let j = 0; j < arr.length; j++) {
if (i !== j) {
temp += arr[j]
}
}
res.push(temp)
temp = 0
}
console.log(res1);
console.log(res);
}
let arr = [2, 7, 11, 4, -2];
console.log(CheckArr(arr));
// [ 20, 15, 11, 18, 24 ]
Let arr=[2,7,11,4,-2]
Let sum=arr.reduce(
(tatal,num)=>{
return tatal+num
},0)
Let new_arr=[];
for(let i = 0; i
Superb👌
let nums = [2, 7, 11, 4, - 2]; let total = nums.reduce((a, b) => a + b);
let sums = nums.map(num => total - num);
console.log(sums);
How it to be solved with map 🤔
@@Factvideo014 👏👏
// sum of all elements except that index element
function arrayOfSum(ar){
let sum=ar.reduce((acc,ele)=>acc+ele);
let finalAr=[];
ar.map(ele=>{
finalAr.push(sum-ele);
})
return finalAr;
}
arrayOfSum([2,7,11,4,-2]);
1st :
const code = (arr)=> {
return arr.map((el, ind) => {
let sum = 0
arr.forEach((item, index) => {
if(ind !== index){
sum+=item
}
})
return sum
})
}
const input = [2, 7, 11, 4, -2];
function sum(){
let sum;
const SUMS = [];
for(let i=0; i
const data = [2, 7, 11, 4, -2]
const outputArr = []
for(let i =0; i < data.length; i ++ ) {
let sum = 0;
for(let j =0; j < data.length; j ++) {
if( data[i] !== data[j]){
sum = sum + data[j]
}
}
outputArr.push(sum)
}
console.log(outputArr)
const A = [2,7,11,4,-2];
const newArr = [];
function fun(array){
for (let index = 0; index < array.length; index++) {
let sum = 0;
array.forEach((e,i) => {
if(index != i) {
sum = sum + e;
}
});
newArr.push(sum)
}
console.log(newArr);
}
fun(A)
his solution
let arr = [2,7,11,4,-2];
let resArr = [...arr];
resArr.reverse();
let left = [0];
let right = [0];
let output = [];
for(let i = 1 ; i< arr.length;i++){
left[i] = left[i-1] + arr[i-1];
right[i] = right[i-1] + resArr[i-1];
}
for(let i = 0 ; i < arr.length;i++){
output.push(left[i]+right[arr.length-1-i])
}
console.log(output)
My answer for Sum 1:
var arr1 = [2,7,11,4,-2];
var sum = arr1.reduce((first,second) => {
return first+second;
});
var newArray = [];
for(let i of arr1){
var NewOne = sum - i;
newArray.push(NewOne);
}
console.log(newArray);
let totalSum=0;
arr.forEach((value)=>{
totalSum+=value
})
const result=arr.map((value)=>{
return totalSum-value
})
console.log(result)
Easiest way 😉
const arr = [2,7,11,4,-2];
let newArr = []
arr.indexOf(5);
arr.forEach((num,i) =>{
let sum = 0;
arr.forEach(n =>
if(n !== num){
sum+=n
});
newArr[i] = sum;
});
console.log(newArr)
function sumof(input){
let output=[]
let sum=0
for(let i=0;i
//without nested for loop for begineer
let input = [2,7,11,4,-2];
let output = []
let sum = 0
for(i in input){
sum += input[i];
}
for(i in input){
output.push(sum - input[i])
}
console.log(output)
I think without nested loop is better solution most of times. As code becomes less complex
everyone in comments just posting copied code from chat gpt instead of apprecating the guy who has a most different approch to solve the problem even though it was very comples but still i was there sitting i would simply have quited
const input = [2, 7, 11, 4, -2];
let output = [];
input.forEach(element => {
let sum = 0;
input.forEach(allElement => {
if(element !== allElement) {
sum += allElement;
}
});
output.push(sum);
});
console.log(output); // [20, 15, 11, 18, 24];
I got the same output doing time com of O(n)
I think u could optimize it a little bit 😉.
let a=[2,4,11,23,-3];
let sum=0;
let b =[];
let n=0;
while(n!=5){
for(let i=0;i
const result=[]
for(let i=0;i
You can improve this solution, without using nested for loops.
const arr = [2,7,11,4,-2];
const result = arr.map((v) => arr.reduce((pv, cv) => pv += cv, 0) - v);
console.log(result); // [20,15,11,18,24]
Shortness wise good. but you can catch that REDUCE code will be running un-necessary many times here.
Time complexity = O(n^2)
You can first calculate the sum of all numbers. Then use for-loop and minus from each number. You'll get O(2n) ~ O(n)
How to contact you man your questions are related to very deep understanding
Mail address is in about section. Also for session we launch a form evry now and then on community posts
Bhai yeh bhi mention kr diya kro ki yeh freshers hai ya experience.
most interviews are fresher
Filter , reduce use kro 10 line ka cide hai
Let input=[4,7,3,9]
Input.reduce((sum,cur)=>sum+cur)
Let output = input.map((cur)=>sum-cur);
Logic seems right. But variables kuch kam nhi hogye..
@@coderdost let input=[4,7,3,9]
let sum = input.reduce((sum,cur)=>sum+cur);
let output = input.map((cur)=>sum-cur);
console.log(output);
Dost! I wonder how you select these candidates to interview. Are they are your subscribers, or ......
anyone can apply. I publish FORM regularly. next form will come in 1-2 days. on community post
form is available now
bro js interview coding vedios cheyyandi bro
const input = [2, 7, 11, 4, -2];
let count = [];
for (let i = 0; i < input.length; i++) {
let sum = 0;
for (let j = 0; j < input.length; j++) {
if (i != j) {
sum = sum + input[j]
}
}
count.push(sum)
}
console.log("Sum Of Element of an array ", count)
//Given Input Arr
const inputArr = [2, 7, 11, 4, -2];
//New Empty Array
const newArr = [];
//
const sumArr = (inputArr) => {
inputArr.forEach((num) => {
const filterArr = inputArr
.filter((el) => el != num) //will remove current elemnt from array
.reduce((acc, current) => {
// taking sum of remaining
return acc + current;
}, 0); // final return will be sum value
newArr.push(filterArr); //Inserting element into new array
});
return newArr;
};
//
console.log(sumArr(inputArr)); // [ 20, 15, 11, 18, 24 ]
console.log(inputArr); // [ 2, 7, 11, 4, -2 ]
let input = [2,7,11,4,-2]
let output=[20,15,11,18,24]
let newArr = []
let element;
for(let i =0;i
Sum is getting calculated many times. You can try with non nested loop also
@@coderdost
let arr =[2,7,11,4,-2]
let n = arr.length;
let sum =0;
for(let i =0;i
@@NitinSingh-ug5ny good enough
@@coderdost sir here he declared "element" using LET and after then he assigning value inside FOR loop....but let have block scope
@@NitinSingh-ug5ny ..?
let arr=[2,7,11,4,-2]
let newArr=[];
for(let i=0;i
Hi sir , Please check my approach with using a pointer at time O(n2) [edited]
let ans = [];
for(let i=0;i
But this is not O(n). while loop always starting from 0 and going to N - so it will beO(n2)
@@coderdost Yes sir You are right sir , its my mistake ,can is any way we can solve this in order of n ?
@@PHINIxXGaming The trick here is that : (SUM of ARRAY - Current element) will give us the solution. so its O(n)
Why he is making this simple question so complicated?
Pressure of interview , makes it difficult
@@coderdost real truth... Also happen with me
This types guys are there in big MNC companies 🤣🤣
There are just talking too much but coding knowledge is nothing
Simplest code just tooked me 10mins to solve, this guy is hilarious 🤣🤣😂😂
const input = [2, 7, 11, 4, -2];
const output = input.map((el, i, arr) => {
const sumableElms = arr.map((elm, ind) => {
return i === ind ? 0 : elm;
});
let sum = 0;
sumableElms.map((elm) => {
return (sum += elm);
});
return sum;
});
console.log("Output : ", output);
Easy for Beginners
thanks me later
// [2,7,11,4,-2]
// [20,15,11,18,24]
let array = [2, 7, 11, 4, -2];
let answer = [];
for (let i = array.length-1; i >= 0; i--)
{
let temp = 0;
for (let j = array.length-1; j >= 0; j--)
{
if (j === i) {
continue;
}
temp = temp + array[j];
if (j == 0) {
answer.unshift(temp)
}
}
if (i == 0)
{
temp = 0
for (let j = 1; j
Sir experience bhi dalo plz ,
This interview was of few months experienced developer
@@coderdost plz upload for experience people as well i.e 2.5-3 years of experience
I think bro didn’t got the question
const arr = [1,2,3,4]
const sum = arr.reduce((a,b)=>{
return a + b
})
const outputArr = arr.map((item, index)=>{
return sum - arr[index]
})
console.log(outputArr)
let sum=0, output=[];
for(let i=0; i
Hey I want you to take my live coding interview.
You can apply once form is again available. we will post on community post soon.
@@coderdost I will be waiting for it
@@prakashbanjade4374 form is availabe now
@@coderdost OK done
@@prakashbanjade4374 great. check your email tonight or tomorrow for final confirmation
Sir reactjs ka bhi coding round
Frontend coding hard h… ab next rkhenge
@@coderdost if we practice 5-6 coding problems in react also then we would really excel from then !!
@@PIYUSH-lz1zq yes, lets see who is up for this live coding in react challenge. Most people are experts in React concepts and problem solving in JS coding. But many people remain out of touch of really coding in Applications .. like really coding small UI problems and things,..
We will search for those Heroes 🫡
let arr1 = [2,7,11,4,-2];
let sum=0;
for(let i=0;i
const arr = [2, 7, 11, 4, -2];
const newArr = [];
const sumExceptCurrentVal = () => {
let currentIndex = 0
let sum = 0;
while(arr.length - 1 >= currentIndex){
for(let i = 0; i < arr.length; i++){
if(currentIndex !== i){
sum += arr[i]
}
}
newArr.push(sum)
currentIndex++;
sum = 0
}
return newArr
}
console.log(sumExceptCurrentVal()) // [20, 15, 11, 18, 24]
let final=[]
tab.forEach((val,i)=>{
final.push( tab.filter(val1=>val1!==val).reduce((a,b)=>a+b,0) )
})
console.log(final) // [20,15,11,18,24]