Javascript LIVE Coding Interview (Mock)

Ғылым және технология

We had an interview with Raghbir Singh who is a Non-CS student. He is preparing for coding interviews at various companies. We took this interview Live via Zoom call.
Raghbir Singh's Linkedin: / raghbir-singh-a1183a219
🤯 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/courses
🔴 Full Projects List : coderdost.com/projects
💾 Source Codes at : github.com/coderdost

Пікірлер: 165

  • @coderdost
    @coderdost Жыл бұрын

    React 2023 MasterClass : bit.ly/3I7MYN7 React Interviews : bit.ly/3QAjAln JavaScript Interview Shorts: bit.ly/3XhHRQ1 React Interview Shorts : bit.ly/3VfIrMi Candidate : Raghbir Singh : www.linkedin.com/in/raghbir-singh-a1183a219/ Interviewer: Abhishek Rathore : www.linkedin.com/in/abhishek87/ More REACT Interviews - bit.ly/3QAjAln REACT Interview Shorts : bit.ly/3VfIrMi JAVASCRIPT Interview Shorts: bit.ly/3XhHRQ1 REACT JS Course (Redux & HOOKS) : bit.ly/3iMethN Course of JAVASCRIPT : bit.ly/3u049tf Course of Modern JS.(ES6) : bit.ly/3DvYCh6

  • @krishnodas6678

    @krishnodas6678

    Жыл бұрын

    In question 1 it is just matching the same indices in both object How the program is figuring out e:12

  • @shivagyawali2590
    @shivagyawali2590 Жыл бұрын

    const input1 = { a: 1, b: 2, c: 3, d: 10, e: 12 }; const input2 = { a: 2, e: 12, f: 6, d: 10 }; let output = {}; Object.keys(input1).forEach((item) => { if (input2[item] === input1[item]) { output[item] = input1[item]; } }); console.log(output);

  • @mitesh_S
    @mitesh_S Жыл бұрын

    Question 3. const input = [2,7, 11,4, -2]; const output = [11,4, -2, 2, 7]; Solution: const input = [2,7, 11,4, -2]; input.push(input.shift()); input.push(input.shift()); console.log(input);

  • @codewithadii

    @codewithadii

    Жыл бұрын

    its better approach

  • @nitishgupta8393

    @nitishgupta8393

    Жыл бұрын

    smart, but interviwer always wants you to solve without any inbuilt method. to see you logic.

  • @chandanthakur5236
    @chandanthakur523611 ай бұрын

    Abhishek is a very patient and makes the interviewee comfortable. Loved it!

  • @user-by1gc9xr8u
    @user-by1gc9xr8u Жыл бұрын

    I am not a js user but I have a logic for Question 3 which is in cpp int rotate(vector& nums, int k) { vector temp(nums.size()); for(int i = 0 ; i

  • @demo5357
    @demo53577 ай бұрын

    I have discovered your channel just a month ago , and seriously I gain much more confidence on JavaScript then before. Sir You are a great teacher❤❤Your every video really a masterpiece . Thank you so much sir. Please upload content on live small React project. Currently I am learning React. Paid courses also have no compare to your content,100% True solid knowledge. "Agar koi aeisa banda bhi aapka video dekh liya ekbar,jisko kuch knowledge hi nhi hai, vo bhi 3 months mei ek front end developer ban sakta hai" great teacher ! great content ! this channel really deserve Millions of views.

  • @bardenishi4312
    @bardenishi4312 Жыл бұрын

    fabulous content it really very helpful

  • @ramireddypanditi6823
    @ramireddypanditi68238 ай бұрын

    This video was greatefull who are learing and wants to become as programmer for fresh beginning

  • @rogeramv
    @rogeramv6 ай бұрын

    in solution 3 : you can use a recursive reverse array approach to reduce time complexity to O(2n)

  • @shaikhjuber7770
    @shaikhjuber7770 Жыл бұрын

    Very useful Video 👍

  • @pritamkeshri8389
    @pritamkeshri8389 Жыл бұрын

    Awesome keep making such video

  • @Aman-kb9gb
    @Aman-kb9gb Жыл бұрын

    let input1 = {a:1, b:2 , c:3 ,d:4} let input2 = {a:3, b:2, e:4 , d:4} for (const key1 in input1) { if (key1 in input2 && input1[key1] === input2[key1]) { console.log(key1, input1[key1]); } }

  • @shahhussain56
    @shahhussain56 Жыл бұрын

    Sir I am requesting you please make a series on DSA in JavaScript for beginners 🥲 🙏🏼

  • @coderdost

    @coderdost

    Жыл бұрын

    Noted. This already in listed but will require some time. As beginners DSA and then advanced DSA lot of topics are there

  • @shahhussain56

    @shahhussain56

    Жыл бұрын

    @@coderdost Thank you so much sir. I will finish first your MERN stack videos and wait for the DSA.

  • @karanbhoite9552

    @karanbhoite9552

    Жыл бұрын

    @@coderdost Is dsa really required , if we are working as frontend dev, and if needed then how much .?

  • @coderdost

    @coderdost

    Жыл бұрын

    @@karanbhoite9552 DSA is required for cracking some good jobs, I haven't find any use of DSA for junior developers (although some dsa basics can help in writing good code, but those are very easy ones) . When you become senior there are chances that you will build some systems and they might need to have better data structure. But in front-end that kind of complete architecture is designed only by really expreience developer (5-10 yrs). Majorly people learn DSA for job interviews. Hope that trend ends

  • @AnkitKumar-xy1xo

    @AnkitKumar-xy1xo

    10 ай бұрын

    Don't learn dsa in JavaScript. It would be better to pick some other language like c++.

  • @mysteryman2213
    @mysteryman2213 Жыл бұрын

    to find second largest number : //asumming there atleast 2 numbers in array nums=[2,45,3,4,2,9,45] // initializing max which will keep track of max int and res which will be second largest let max=nums[0] let res=nums[1] if(nums[1]>nums[0]){ max=nums[1] res=nums[0] } //starting loop from the third number coz first two are already assigned; for(let i=2; imax){ res=max max=nums[i] } else if(nums[i]>res && nums[i] !=max){ res=nums[i] } } console.log(res) TIME COMPLEXITY O(N) only traversing through entire array once SPACE O(1)

  • @jsagar95
    @jsagar95 Жыл бұрын

    Thanks for uploading!

  • @mufadal8264
    @mufadal8264 Жыл бұрын

    1st question let input1 = {a:1,b:2,c:4,f:11,t:10} let input2 = {a:2,b:2,c:3,f:11} // take out common key with same value {b:2,f:11} console.log(TakeOutCommon(input1,input2)) ***CODE*** function TakeOutCommon(ob1,ob2){ if(Object.keys(ob1).length===0 || Object.keys(ob2).length===0)return {} // if any input object is empty let ansObject = {} for(let k in ob1){ if( ( ob1[k] && ob2[k] ) && ob1[k]===ob2[k]){ // checking if both object have same key..... if they have same key then checking for its value ansObject[k]=ob1[k] } } return ansObject }

  • @nachiketdorkulkar7114
    @nachiketdorkulkar7114 Жыл бұрын

    Thanks sir for mock Interview

  • @akshatsharma880
    @akshatsharma880 Жыл бұрын

    Nice, It was a helpful video

  • @genius._bro
    @genius._bro6 ай бұрын

    vscode text-editor are allow or not?

  • @rakeshjha6492
    @rakeshjha6492 Жыл бұрын

    Really so helpful.

  • @ashurajput357
    @ashurajput357 Жыл бұрын

    For the second question it is ok to sort array in descending order and then make two a,b and using shift to remove the first element .and b will have value of 7 second largest element from array1

  • @coderdost

    @coderdost

    Жыл бұрын

    No. As we can also have repeated numbers so its not sure that sorted 2nd index will give the result

  • @codewithadii
    @codewithadii Жыл бұрын

    in 2nd question i think the using of set method is good instead of solving with complexity

  • @vaibhavjaiswal1309

    @vaibhavjaiswal1309

    9 ай бұрын

    you can directly solve that question in o(N) with help of two variable in single loop

  • @codewithadii

    @codewithadii

    9 ай бұрын

    @@vaibhavjaiswal1309 yes you are right

  • @AmitPandey_10
    @AmitPandey_108 ай бұрын

    I am familiar with some of the concepts of DSA but not all and currently i am learning web development and want to get hired off campus because i've been completed my graduation so should i have to learn dsa and solve questions or i just focus on technology and try to build projects.

  • @Its_Abhi_Thakur
    @Its_Abhi_Thakur Жыл бұрын

    Very helpful 👍

  • @harithati501
    @harithati501 Жыл бұрын

    please release as many videos as possible it would be helpful for us who are learning programming from youtube

  • @coderdost

    @coderdost

    Жыл бұрын

    yes trying that. will soon have more videos

  • @JAYPATEL-hn2nn
    @JAYPATEL-hn2nn Жыл бұрын

    U can do Let input=[2,7,11,4,-2] for(let I =0; I

  • @JAYPATEL-hn2nn

    @JAYPATEL-hn2nn

    Жыл бұрын

    In this way u can do this left or right using pop,push, shift and unshift

  • @yournanban3812
    @yournanban381216 күн бұрын

    const input = [2, 7, 11, 4, -2] let spl = input.splice(0, 2) console.log(spl); //[2,7] console.log(input); //[11,4,-2] output = input.concat(spl) //1. using concat to merge 2 arrays // output = [...input, ...spl] //2. using spread operator to merge 2 arrays // output = input.push(...spl) //3. Merge using array.push() console.log(output) //output = [11,4,-2, 2, 7]

  • @rushabhdave6648
    @rushabhdave6648 Жыл бұрын

    question : 1 ES6 version const obj1 = {a : 1, b : 2, c : 3, d: 4, e : 5} const obj2 = {e : 4, c : 3, r : 6, a:1, f : 9, p : 4} const keys1 = Object.keys(obj1) const keys2 = Object.keys(obj2) const resultObject = {} const commonKeyCollector = keys1 > keys2 ? keys2.filter((key2) => keys1.includes(key2)) : keys1.filter((key1) => keys2.includes(key1)) commonKeyCollector.map((key) => { if(obj1[key] === obj2[key]){ resultObject[key] = obj1[key] }}) console.log(resultObject)

  • @amazondeals7284
    @amazondeals728410 ай бұрын

    Solution 2. I didn't used any inbuilt function. Is my approach right? let arr = [1,2,-2,11,7,1] let big = arr[0]; let big2; let bigI; for(let i=0; i

  • @happylaughy2777
    @happylaughy27779 ай бұрын

    I solved the 1st problem in this way cause I thought we can't loop through objects directly😆😆😆 function objCompare(a, b){ const first=Object.entries(a) const second=Object.entries(b) let arr=[] for(let i=0;i

  • @AdarshMitr
    @AdarshMitr Жыл бұрын

    Question-3 const input=[2,7,11,4,-2,]; const output=[11,4,-2,2,7]; Solution: function rotateArr(input){ let result=[]; for(let i=2;i

  • @praveen3794
    @praveen3794 Жыл бұрын

    Subscribed🎉

  • @akash_gupta_2090
    @akash_gupta_2090 Жыл бұрын

    const value_1 = [1, 2, -2, 11, 7, 1]; // output 7 const value_2 = [1, 4, 7, 2, 4, 7]; // output 4 function nextBiggest(arr) { let max = 0, result = 0; for (const value of arr) { if (value > max) { result = max; max = value; } else if (value result) { result = value; } } return result; }

  • @rishabrajverma2883

    @rishabrajverma2883

    Жыл бұрын

    let arr=[5,4,8,2,3,6]; function Secondlargest(arr){ return arr.sort()[arr.length-2]; } console.log(Secondlargest(arr));

  • @SKINS-WITH-NO-SKILLS
    @SKINS-WITH-NO-SKILLS Жыл бұрын

    It will be easy if you used inbuilt functions

  • @devjariwala.j
    @devjariwala.j8 ай бұрын

    Question 3 : const input = [2, 7, 11, 4, -2]; function rot2IndLeft(array) { let output = []; for (let i = 2; i output.push(array[i]); } output.push(array[0], array[1]); console.log(array); return output; } const output = rot2IndLeft(input); console.log(output);

  • @tonmaysardar3331
    @tonmaysardar3331 Жыл бұрын

    const input=[1,4,7,2,4,7] let a=0; let b; for (let i=0;ia){ b=a; a=input[i] } } console.log(b)

  • @Lucky-po5ih
    @Lucky-po5ih Жыл бұрын

    const arr=[1,5,-2,11,7] let res= arr.sort() console.log(res[arr.length-1])

  • @user-iw8vo4nc6h
    @user-iw8vo4nc6h Жыл бұрын

    Thanks Bhai.....

  • @ArunKumar-gx8iv
    @ArunKumar-gx8iv Жыл бұрын

    we can find the second item in the array in just one iteration ,just maintaining two Fmax,Smax ,Variable,Time complexity =O(N) . we do not need to sort the array and also no need of set ds

  • @coderdost

    @coderdost

    Жыл бұрын

    Great. Can you share this solution.

  • @ArunKumar-gx8iv

    @ArunKumar-gx8iv

    Жыл бұрын

    @@coderdost As i Am A Java Guy ,Currently Learning JS from Your videos JAVA CODE: Time Complexity =O(N) AND SC=O(1) static int getSecondLargestItem(int[] arr) { int n=arr.length; //if array Length is less than 2 then,there is no second largest item if(nS_max && arr[i]!=F_max){ S_max=arr[i]; //update second-largest item } } return S_max; } But Equivalent JAVASCRIPT CODE : function getSecondLargestItem(arr) { var n = arr.length; //if array Length is less than 2 then,there is no second largest item if (n return -1; } var F_max = Number.MIN_SAFE_INTEGER; //First-largest item in an array var S_max = Number.MIN_SAFE_INTEGER; //Second-largest item in an array for (var i = 0; i //check if current element is greater than first-largest item if (arr[i] > F_max) { S_max = F_max; //update second-largest item F_max = arr[i]; //update first-largest item } //check if current element is greater than second-largest item and not equal to first-largest item else if (arr[i] > S_max && arr[i] != F_max) { S_max = arr[i]; //update second-largest item } } return S_max; }

  • @coderdost

    @coderdost

    Жыл бұрын

    @@ArunKumar-gx8iv Great Approach.

  • @buntyjavia7740
    @buntyjavia7740 Жыл бұрын

    let input = [1,4,7,2,4,7] function secondLargest(input) { let num = [...new Set(input)].sort().reverse() console.log(num[1]); } secondLargest(input) is it right????

  • @PHINIxXGaming
    @PHINIxXGaming Жыл бұрын

    Hi sir , this is my solution of finding 2nd largest element; *Not use of reverse inbuilt function function find2ndlargest(arr) { let smax = 0; let stack = []; for (let i = 0; i while (stack.length !== 0 && stack[stack.length - 1] smax = stack[stack.length - 1]; stack.pop(); } stack.push(arr[i]); } return smax; } console.log(find2ndlargest(arr));

  • @95keshavsharma
    @95keshavsharma Жыл бұрын

    question 2 function task2(arr) { let arrCopy = arr.slice().sort((a, b) => b - a); // reverse sort let output = arrCopy.find((x) => x return output }

  • @khaung4413
    @khaung44135 ай бұрын

    You said he is a non CS-student but how does he know these algorithms though?

  • @nitishgupta8393
    @nitishgupta8393 Жыл бұрын

    q3: const rotate2place = (arr)=> { let res = [] for (let i=0; i if(i+2 res.push(arr[i+2]) } else { res.push(arr[(i+2) - arr.length ] ) } } return res }

  • @AbhishekTrivedi07
    @AbhishekTrivedi07 Жыл бұрын

    I usually reject the candidate if he/she use Array.sort() for finding the second largest element. I expect this answer to be solved in O(n) instead of using Array.sort() which takes O(nlogn). People use the sort method blindly, without even realising the time complexity.

  • @succeedwithuttam2271

    @succeedwithuttam2271

    Жыл бұрын

    How to find second largest number in native javascript: nums=[2,45,3,4,2,9,45] max=nums[0] secondmax = Number.NEGATIVE_INFINITY //finding largest number nums.map((num)=>{ if(num > max){ max=num } }) //removing largest number const arr = nums.filter(function(item) { return item !== max }) //finding second largest number arr.map((num)=>{ if(num > secondmax){ secondmax=num } }) console.log(arr) console.log(max) console.log(secondmax)

  • @AbhishekTrivedi07

    @AbhishekTrivedi07

    Жыл бұрын

    @@succeedwithuttam2271 - Why are you removing the max from the array? You can use it to find 2nd Max. In fact, you can do all this in a single loop, which will be the optimised solution.

  • @mysteryman2213

    @mysteryman2213

    Жыл бұрын

    ​@@AbhishekTrivedi07 to find second largest number : //asumming there atleast 2 numbers in array nums=[2,45,3,4,2,9,45] // initializing max which will keep track of max int and res which will be second largest let max=nums[0] let res=nums[1] if(nums[1]>nums[0]){ max=nums[1] res=nums[0] } //starting loop from the third number coz first two are already assigned; for(let i=2; imax){ res=max max=nums[i] } else if(nums[i]>res && nums[i] !=max){ res=nums[i] } } console.log(res) TIME COMPLEXITY O(N) only traversing through entire array once SPACE O(1)

  • @a.spragadeeshbalaji2917

    @a.spragadeeshbalaji2917

    4 ай бұрын

    const arr = [2,4,5,3,4,2,9,45]; //sorting the array for(let i=0,j=1;j arr[j]){ arr[j] = arr[i] + arr[j]; arr[i] = arr[j] - arr[i]; arr[j] = arr[j] - arr[i]; } } console.log("The second largest number in this array is "+arr[arr.length - 2]);

  • @user-vq3hw1gp5g
    @user-vq3hw1gp5g Жыл бұрын

    last one : const rotate = (arr) =>{ let res = arr.splice(0,2) arr.push(...res) return arr } console.log(rotate(arrVal))

  • @lalitsinghnegi1562
    @lalitsinghnegi1562 Жыл бұрын

    // question 1 // const input_1 = { a:1 , b:2 , c:3, d:10 , e:12 } // const input_2 = { a:2 , e:12 , f:6, d:10 } // const output = {} // for(let item in input_1){ // if(input_1[item] === input_2[item]){ // output[item] = input_1[item] // } // } // console.log(output) // question 2 // const input_1 = [1,2,-2,11,7,1] // const temp = Math.max(...input_1) // const temp_2 = input_1.filter(item => item != temp) // const result = Math.max(...temp_2) // console.log(result) // question 2 // let max_1 = -Infinity; // let max_2 = -Infinity; // for(let item of input_1){ // if(item > max_1){ // max_2 = max_1 // max_1 = item // } // else{ // if(item > max_2) // { // max_2 = item // } // } // } // console.log(max_2) // question 3 // const input = [2,7,11,4,-2] // const result = [...input] // for(let index in input){ // result.splice(index - 2 , 1 , input[index]) // } // console.log(result);

  • @anandsen8893

    @anandsen8893

    Жыл бұрын

    Salary kitne loge discuss kar le 😉

  • @lalitsinghnegi1562

    @lalitsinghnegi1562

    Жыл бұрын

    @@anandsen8893 jitne se ghar chl jaye utni dedo sir ...

  • @enthusiatic_coder6801
    @enthusiatic_coder6801 Жыл бұрын

    solution for rotation of the array llet input1 = [2, 7, 11, 8, 19]; const rotateArray = (input) => { for (let i = 0; i if (input1[i] === input) { input1[i - 2] === undefined && input1.push(input1[i]) && input1.shif(); input1[i] = input1[i - 1]; input1[i - 1] = input1[i - 2]; input1[i - 2] = input; break; } } console.log(input1); }; rotateArray(input1[3]);

  • @supriyasaha5234
    @supriyasaha5234 Жыл бұрын

    const input = [2, 5, 7, 8, 3, 4]; // output should be [7,8,3,4,2,5] const output = []; function main(reverseVal) { for (let i = reverseVal; i

  • @fancybeing1296
    @fancybeing1296 Жыл бұрын

    1st question --> const input = [1, 2, -2, 11, 7, 1] function scndLarg(arr) { let newArr = arr.sort((a, b) => a - b); let val = [] for (let i = 0; i if (!val.includes(newArr[i])) { val.push(newArr[i]) } } return val[val.length -2] }

  • @sumit22873
    @sumit22873 Жыл бұрын

    nice sir

  • @khanapeena2191
    @khanapeena2191Ай бұрын

    pajji cha gye tusse

  • @Viral_Shorts_v
    @Viral_Shorts_v Жыл бұрын

    const input = [1,3,5,6,3,-1] const output= [5,6,3,-1,1,3] const rotateArr =(arr,numberOfRotation=0)=>{ if (numberOfRotation>0){ let temp = arr.pop() arr.unshift(temp); } return arr } console.log(rotateArr(input,2))

  • @raghbirsingh8585
    @raghbirsingh8585 Жыл бұрын

    ♥️

  • @rahuldravid5594
    @rahuldravid559410 ай бұрын

    function secondLargest(input1){ input1.sort((a,b)=>b-a); for(let i=0;i

  • @sushantsaud7297
    @sushantsaud72979 ай бұрын

    et input1 = [1, 2, -2, 11, 7, 1, 11, 12]; let input2 = [1, 4, 2, 4, 7]; function getSecondValue(input) { let data = input.sort((a, b) => { return a - b; }); return data; } let val = getSecondValue(input2); console.log(val); for (let i = 0; i if (i === val.length - 2) { console.log(val[i]); break; } }

  • @pawansinghrawat7886
    @pawansinghrawat78869 ай бұрын

    ques1:Better approach const output = {}; for (const key in obj1) { if (obj2.hasOwnProperty(key) && obj1[key] === obj2[key]) { output[key] = obj1[key]; } } console.log(output);

  • @suryatejaparvata
    @suryatejaparvata Жыл бұрын

    👍🏻

  • @rahuldravid5594
    @rahuldravid559410 ай бұрын

    const input1=[1,2,11,22,33,44,22,33,44]; let input2=Array.from(new Set(input1)); input2.sort((a,b)=>b-a); console.log(input2[1]);

  • @cstej
    @cstej Жыл бұрын

    /** Question Number 2 */ const input = [1,2,-2,11,7,1] input.sort((a,b)=> b-a) function secondLargest(input){ for(value of input){ let temp=input[0] if(value!==temp){ return value break } } } const result = secondLargest(input) console.log(result)

  • @95keshavsharma
    @95keshavsharma Жыл бұрын

    question 3 function task3(arr, elemPosition) { let arrCopy = [...arr]; let arr2 = arrCopy.splice(elemPosition); return [...arr2, ...arrCopy]; }

  • @kt399
    @kt399 Жыл бұрын

    question 1: const input1 = {a:1, b:2, c:3, d:10, e:12} const input2 = {a:2, e:12, f:6, d:10} let output = {} for(let [key, value] of Object.entries(input1)) { if(input2[key] === value) { output[key] = value } } console.log(output)

  • @nimmanasss
    @nimmanasss Жыл бұрын

    🥰🥰🥰

  • @Foodish_fun
    @Foodish_fun Жыл бұрын

    second question ---- const secLar = function (arr) { const max = Math.max(...arr); const index = arr.indexOf(max); const del = arr.splice(index, 1); const maxNew = Math.max(...arr); console.log(maxNew); } secLar(arr);

  • @rishabrajverma2883

    @rishabrajverma2883

    Жыл бұрын

    let arr=[5,4,8,2,3,6]; function Secondlargest(arr){ return arr.sort()[arr.length-2]; } console.log(Secondlargest(arr));

  • @nitishgupta8393
    @nitishgupta8393 Жыл бұрын

    my sol: const inp1 = {a:1, b:2, c:3, d:10, e:12} const inp2 = {a:2, e:12, f:6, d:10} let common = {} Object.entries(inp1).forEach(([key,val])=> { Object.entries(inp2).forEach(([k,v])=>{ if(key == k && val ==v){ common[key] = val } }) }) console.log(common)

  • @SagarTakoresdt
    @SagarTakoresdt Жыл бұрын

    20:22, const arr = [2, 7, 11, 4, -2]; const arr1 = arr.splice(0,2); console.log([...arr, ...arr1]) how's this approach?

  • @coderdost

    @coderdost

    Жыл бұрын

    it's fine to do it in a real life project. In that interview I think generally we want for-loop based without using in-built functions.. Just to check how one thinks about building logics

  • @SagarTakoresdt

    @SagarTakoresdt

    Жыл бұрын

    ​@@coderdost Your KZread shorts are very helpful, in real project.

  • @susheelkumar6266
    @susheelkumar62662 ай бұрын

    He already used sort He has to just print length-2

  • @connectwithkoushik
    @connectwithkoushik9 ай бұрын

    //Rotate array const input = [2, 7, 11, -2, 4]; const removeValue = input.splice(0, 2); input.push(...removeValue);

  • @PHINIxXGaming
    @PHINIxXGaming Жыл бұрын

    Sir this is my solution for the 1st question: ---> let input1 = { a: 1, b: 2, c: 3, d: 10, e: 12 }; let input2 = { a: 2, e: 12, f: 6, d: 10 }; let obj = {}; function findkeyValue(input1, input2) { for (let key in input1) { if (input1[key] == input2[key]) { if (obj[key] == undefined) { obj[key] = input1[key]; } } } return obj; } console.log(findkeyValue());

  • @coderdost

    @coderdost

    Жыл бұрын

    its fine. if (obj[key] == undefined) {

  • @PHINIxXGaming

    @PHINIxXGaming

    Жыл бұрын

    @@coderdost oook sir thank you 😊

  • @ishinchanzod3641
    @ishinchanzod3641 Жыл бұрын

    const returnCommonvalue=(input1,input2)=>{ let dict = {}; for(let key in input1) { if(key in input2 && input1[key] === input2[key]) { dict[key] = input1[key]; } } return dict }

  • @karanbhoite9552
    @karanbhoite9552 Жыл бұрын

    lets asume that input1 has 100 entries and input2 has only 3 or 4 entries then above code wouldn't be appropriate below code might solve this issue function func(input1,input2){ let obj = {} if(Object.keys(input1).length > Object.keys(input2).length){ for(let i in input2){ if(input2[i]==input1[i]){ obj[i] = input2[i] } } }else{ for(let i in input1){ if(input1[i]==input2[i]){ obj[i] = input1[i] } } } return obj }

  • @amazondeals7284
    @amazondeals728410 ай бұрын

    Solution 3: const input = [2,7,11,4,-2] let temp = [] for(let i=0; i if(i

  • @dheerajsingh2425
    @dheerajsingh2425 Жыл бұрын

    let array = [9,1,4,3,7,2,11] let largest = 0; let secondLargest = 0; let i = 0; while(i array[i] && secondLargest secondLargest = array[i] } i++; }

  • @satyaranjanbehera
    @satyaranjanbehera Жыл бұрын

    where will i get this type of javascript question ?

  • @coderdost

    @coderdost

    Жыл бұрын

    There are many sites like Geek for geeks.. leetcode etc

  • @mobpsycho6600
    @mobpsycho6600 Жыл бұрын

    Sir please make a video on how to do async operations in redux/toolkit

  • @coderdost

    @coderdost

    Жыл бұрын

    This will be covered in upcoming series of react JS. Thanks for suggestions.

  • @mobpsycho6600

    @mobpsycho6600

    Жыл бұрын

    @@coderdost and one more thing please make it fully dependent on the redux 😁

  • @devjariwala.j
    @devjariwala.j8 ай бұрын

    Question 1 : your candidate is looping in only input 1 which will fail if input 2 is bigger than input 1 here is correct answer const input1 = { a: 1, b: 2, c: 3, d: 10, name: "dev" }; const input2 = { a: 2, name: "dev", f: 6, d: 10 }; function commonValues(input1, input2) { console.log("Input 1 :", input1); console.log("Input 2 :", input2); let obj = {}; for (let key1 in input1) { if (input2.hasOwnProperty(key1) && input1[key1] === input2[key1]) { obj[key1] = input1[key1]; } } return obj; } const output = commonValues(input1, input2); console.log("Output : ", output);

  • @sahilsawant1140
    @sahilsawant114011 ай бұрын

    3 rd problem solution: const input=[2,7,11,4,-2] for(let i=0;i

  • @nitinjoshi6533
    @nitinjoshi6533 Жыл бұрын

    solution to the second question let a=[1,4,7,2,4,7] let sortedArr=a.sort((a,b)=>a-b) let uniqueArr=[...new Set(sortedArr)] let secondLargest=uniqueArr[uniqueArr.length-2] console.log(secondLargest)

  • @allindiachannel2290
    @allindiachannel2290 Жыл бұрын

    Sir how can give this type of mock interview?

  • @coderdost

    @coderdost

    Жыл бұрын

    Post related to such mock interview dates are posted on channel community.

  • @pjgaming6695
    @pjgaming6695 Жыл бұрын

    solved it in 15 seconds

  • @dastaan3468
    @dastaan3468 Жыл бұрын

    Second question. const arr1 = [1, 2, -2, 11, 7, 1]; const arr2 = [1, 4, 7, 2, 4, 7]; function getSecondLargestNum(arr) { const filteredArr = []; const newArr = arr.sort((a, b) => a - b).map(num => filteredArr.includes(num) ? num : filteredArr.push(num)); return filteredArr[filteredArr.length - 2]; } console.log(getSecondLargestNum(arr2));

  • @skyhi9383
    @skyhi9383 Жыл бұрын

    Question2: const SecondLargest = (arr)=>{ // function to store the freq in object. const obj = arr.reduce((acc,currentValue)=>{ acc[currentValue] = (acc[currentValue]|| 0)+1; return acc; },{}); // sort the object. const data = Object.entries(obj).sort((a,b)=>a[0]-b[0]); console.log(data) let n = data.length; if(n return data[n-2][0]; } console.log(SecondLargest(SecondLargest_Input));

  • @rishabrajverma2883

    @rishabrajverma2883

    Жыл бұрын

    let arr=[5,4,8,2,3,6]; function Secondlargest(arr){ return arr.sort()[arr.length-2]; } console.log(Secondlargest(arr));

  • @variant3283

    @variant3283

    Жыл бұрын

    @@rishabrajverma2883 your code wont work when array has repated elements

  • @Shrikant_Jha
    @Shrikant_Jha4 ай бұрын

    const input1 = { a: 1, b: 2, c: 3, d: 10, e: 12, }; const input2 = { a: 2, e: 12, f: 6, d: 10, }; // Function to find common properties with the same values function findcommonInBoth(obj1 ,obj2){ const resultingObj = {}; for (const key in obj1) { if (obj2.hasOwnProperty(key) && obj1[key] === obj2[key]){ //construct a new object resultingObj[key] = obj1[key] } } return resultingObj } const result = findcommonInBoth(input1 ,input2) console.log(result);

  • @ishwarmore3814
    @ishwarmore381411 ай бұрын

    //1 const input1 = { a: 1, b: 2, c: 3, d: 10, e: 12 }; const input2 = { a: 2, e: 12, f: 6, d: 10 }; const op={}; for(key in input1){ if(input1[key]===input2[key]) op[key] = input1[key]; } console.log(op) //2 const input = [2,7,11,4, -2]; const sorted = input.sort((a,b)=>a-b) console.log(sorted.reverse()) //or const cleaned = [...new Set(input)] console.log(cleaned.sort()[cleaned.length -2]) //3 const leftRotate = (arr,by)=>{ if(by>0){ arr[arr.length-1] = arr.shift() leftRotate(arr,by-1) } return arr; } const input = [2,7,11,4, -2]; console.log(leftRotate(input,3))

  • @pradhyumnsharma976
    @pradhyumnsharma976 Жыл бұрын

    Question 3: Solutiion = [...input.slice(2),...input.slice(0,2)]

  • @mdmerajalam4092
    @mdmerajalam4092 Жыл бұрын

    QUS 1 : const input1 = {a: 1, b: 2, d: 3, d: 10, e: 12} const input2 = {a: 2, e: 12, f: 6,d: 10 } let keys = Object.keys(input2) const obj = {} for(let i in input1 ){ if( keys.includes(i) && input1[i] === input2[i] ){ obj[i] = input1[i] } } console.log(obj)

  • @irajeshtailor

    @irajeshtailor

    Жыл бұрын

    This is correct answer

  • @ankittyagi6706
    @ankittyagi67067 ай бұрын

    const input =[1,2,-2,11,7,1] const remDuplicate =[...new Set(input)] console.log(remDuplicate.sort((a,b)=>b-a)[1])

  • @pritamkeshri8389
    @pritamkeshri8389 Жыл бұрын

    const input1 = { a: 1, b: 2, c: 3, d: 10, e: 12 }; const input2 = { a: 2, e: 12, f: 6, d: 10 }; const output1 = { b: 2, c: 3 }; const input1keys = Object.keys(input1); const output2 = {}; input1keys.forEach((key) => { if (input1[key] === input2[key]) { Object.assign(output2, { [key]: input2[key] }); } }); console.log(output2);

  • @davidbaraiya2649
    @davidbaraiya2649 Жыл бұрын

    How many years of experience this guy ?

  • @coderdost

    @coderdost

    Жыл бұрын

    Fresher non IT background

  • @muhammadumerfarooq3156
    @muhammadumerfarooq31564 ай бұрын

    Problem 1: function intersection (obj1,obj2){ let output={} if (Object.keys(obj1).length===0 || Object.keys(obj2).length===0){ return {} } Object.keys(obj1)?.forEach(ele=>{ if(obj1[ele]===obj2[ele]){ output[ele]=obj1[ele] } }) return output }

  • @ashishnirvikar5665
    @ashishnirvikar566511 ай бұрын

    Question 2 : const arr1 = [1,2,-2,11,7,1]; const findMax = Math.max(...arr1); const secondLargest = arr1.filter(num => num console.log(Math.max(...secondLargest));

  • @ArunKumar-gx8iv
    @ArunKumar-gx8iv Жыл бұрын

    We can rotate the any array by k position either left or right most in just O(N) with space Complexity O(1) . we just need to observe the pattern of the output for at least 2 to 4 different input arrays.

  • @coderdost

    @coderdost

    Жыл бұрын

    How to do in O(1) space ?

  • @ArunKumar-gx8iv

    @ArunKumar-gx8iv

    Жыл бұрын

    @@coderdost create a reverse function for reverse // Reverse first n-k elements Reverse(arr, 0, n - k - 1); // Reverse last k elements Reverse(arr, n - k, n - 1); // Reverse whole array Reverse(arr, 0, n - 1); this is for Rotate array by K elements to right

  • @tonmaysardar3331
    @tonmaysardar3331 Жыл бұрын

    const i1={a:1,b:2,c:3,d:10,e:12} const i2={a:2,e:12,f:6,d:10} let output={}; for (let i in i1){ for (let j in i2){ if (i==j && i1[i]==i2[j]){ output[i]=i1[i] } } } console.log(output)

  • @dheerajsingh2425
    @dheerajsingh2425 Жыл бұрын

    let obj = { a:1, b:2, c:3, d:4, e:5 } let obj1 = { a:10, b:20, c:3, d:4, } let result = {} Object.keys(obj).forEach((val)=>{ if(obj[val] === obj1[val]){ result[val] = obj[val] } })

  • @tsv0101
    @tsv010111 ай бұрын

    let arr = [1,3,4,1,264,2311,2311,6]; let [max,secMax] = [-Infinity,-Infinity] for(let i = 0 ; i if(arr[i]>max){ secMax = max max = arr[i] }else if(arr[i]>secMax && arr[i] secMax = arr[i] } } console.log(secMax)

  • @rupbhaiya
    @rupbhaiya Жыл бұрын

    Sir can I get a chance of getting a Mock interview by you?

  • @coderdost

    @coderdost

    Жыл бұрын

    Please fill the Form. weekend - we will again try to have some rounds

  • @rupbhaiya

    @rupbhaiya

    Жыл бұрын

    @@coderdost Sir would you mind give me the link? :(

  • @coderdost

    @coderdost

    Жыл бұрын

    @@rupbhaiya www.geeksforgeeks.org/practice-for-cracking-any-coding-interview/

  • @amazondeals7284
    @amazondeals728410 ай бұрын

    Sir, is this real or fake interview? Please reply 🙏🏼🙏🏼🙏🏼

  • @chandrabhanrahangdale1534

    @chandrabhanrahangdale1534

    9 ай бұрын

    It's is a mock interview

  • @coderdost

    @coderdost

    9 ай бұрын

    practice only

  • @sureshkolla1632
    @sureshkolla1632 Жыл бұрын

    function getCommonProps(input1,input2){ const Input1Keys= Object.keys(input1) const Input2Keys= Object.keys(input2) return Input1Keys.reduce((acc, curr)=>{ if(Input2Keys.includes(curr) && input1[curr] === input2[curr]){ acc[curr]= input1[curr] return acc } return acc },{}) }

  • @bhardwajpradeep
    @bhardwajpradeep Жыл бұрын

    function commonKeys(a, b) { let myObj = {}; Object.keys(a).filter(function (key) { if (a[key] == b[key]) { myObj[key] = b[key]; return b.hasOwnProperty(key); } }); return myObj; } var obj1 = { a: 10, b: 30, c: 60, d: 90, }; var obj2 = { a: 20, b: 40, c: 60, d: 90, }; const data = commonKeys(obj1, obj2); console.log("data", data);

  • @succeedwithuttam2271
    @succeedwithuttam2271 Жыл бұрын

    How to find second largest number in native javascript: nums=[2,45,3,4,2,9,45] max=nums[0] secondmax = Number.NEGATIVE_INFINITY //finding largest number nums.map((num)=>{ if(num > max){ max=num } }) //removing largest number const arr = nums.filter(function(item) { return item !== max }) //finding second largest number arr.map((num)=>{ if(num > secondmax){ secondmax=num } }) console.log(arr) console.log(max) console.log(secondmax)

Келесі