smart, but interviwer always wants you to solve without any inbuilt method. to see you logic.
@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]); } }
@demo5357 Жыл бұрын
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.
@Aadvit-i7t Жыл бұрын
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
@WorldSpace0074 ай бұрын
Can we use reverse function 3 times😊
@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
@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 }
@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)
@JAYPATEL-hn2nn Жыл бұрын
U can do Let input=[2,7,11,4,-2] for(let I =0; I
@JAYPATEL-hn2nn Жыл бұрын
In this way u can do this left or right using pop,push, shift and unshift
@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)
@rogeramv11 ай бұрын
in solution 3 : you can use a recursive reverse array approach to reduce time complexity to O(2n)
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 < max && value > result) { result = value; } } return result; }
@rishabrajverma2883 Жыл бұрын
let arr=[5,4,8,2,3,6]; function Secondlargest(arr){ return arr.sort()[arr.length-2]; } console.log(Secondlargest(arr));
@devjariwala.j Жыл бұрын
Question 3 : const input = [2, 7, 11, 4, -2]; function rot2IndLeft(array) { let output = []; for (let i = 2; i < array.length; i++) { output.push(array[i]); } output.push(array[0], array[1]); console.log(array); return output; } const output = rot2IndLeft(input); console.log(output);
@@anandsen8893 jitne se ghar chl jaye utni dedo sir ...
@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)
@shahhussain56 Жыл бұрын
Sir I am requesting you please make a series on DSA in JavaScript for beginners 🥲 🙏🏼
@coderdost Жыл бұрын
Noted. This already in listed but will require some time. As beginners DSA and then advanced DSA lot of topics are there
@shahhussain56 Жыл бұрын
@@coderdost Thank you so much sir. I will finish first your MERN stack videos and wait for the DSA.
@karanbhoite9552 Жыл бұрын
@@coderdost Is dsa really required , if we are working as frontend dev, and if needed then how much .?
@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 Жыл бұрын
Don't learn dsa in JavaScript. It would be better to pick some other language like c++.
@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 < newArr.length; i++) { if (!val.includes(newArr[i])) { val.push(newArr[i]) } } return val[val.length -2] }
@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)
question 2 function task2(arr) { let arrCopy = arr.slice().sort((a, b) => b - a); // reverse sort let output = arrCopy.find((x) => x < arrCopy[0]); // find will find first elemtent which hold true return output }
@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 Жыл бұрын
let arr=[5,4,8,2,3,6]; function Secondlargest(arr){ return arr.sort()[arr.length-2]; } console.log(Secondlargest(arr));
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]
@sushantsaud7297 Жыл бұрын
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 < val.length; i++) { if (i === val.length - 2) { console.log(val[i]); break; } }
@nitishgupta8393 Жыл бұрын
q3: const rotate2place = (arr)=> { let res = [] for (let i=0; i< arr.length; i++){ if(i+2< arr.length){ res.push(arr[i+2]) } else { res.push(arr[(i+2) - arr.length ] ) } } return res }
solution for rotation of the array llet input1 = [2, 7, 11, 8, 19]; const rotateArray = (input) => { for (let i = 0; i < input1.length; 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]);
@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));
@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] } })
@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)
@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 Жыл бұрын
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 Жыл бұрын
@@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 Жыл бұрын
@@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.spragadeeshbalaji291710 ай бұрын
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]);
@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 Жыл бұрын
No. As we can also have repeated numbers so its not sure that sorted 2nd index will give the result
@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 < arr.length; i++) { while (stack.length !== 0 && stack[stack.length - 1] < arr[i]) { smax = stack[stack.length - 1]; stack.pop(); } stack.push(arr[i]); } return smax; } console.log(find2ndlargest(arr));
@95keshavsharma Жыл бұрын
question 3 function task3(arr, elemPosition) { let arrCopy = [...arr]; let arr2 = arrCopy.splice(elemPosition); return [...arr2, ...arrCopy]; }
@Shrikant_Jha10 ай бұрын
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);
@inspireVoyage123 Жыл бұрын
function secondLargest(input1){ input1.sort((a,b)=>b-a); for(let i=0;i
@happylaughy2777 Жыл бұрын
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
@codewithadii Жыл бұрын
in 2nd question i think the using of set method is good instead of solving with complexity
@vaibhavjaiswal1309 Жыл бұрын
you can directly solve that question in o(N) with help of two variable in single loop
@codewithadii Жыл бұрын
@@vaibhavjaiswal1309 yes you are right
@amazondeals7284 Жыл бұрын
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
@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 < 2) return -1; return data[n-2][0]; } console.log(SecondLargest(SecondLargest_Input));
@rishabrajverma2883 Жыл бұрын
let arr=[5,4,8,2,3,6]; function Secondlargest(arr){ return arr.sort()[arr.length-2]; } console.log(Secondlargest(arr));
@Noobpuzzlesolver Жыл бұрын
@@rishabrajverma2883 your code wont work when array has repated elements
@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());
let array = [9,1,4,3,7,2,11] let largest = 0; let secondLargest = 0; let i = 0; while(i array[i] && secondLargest < array[i]){ secondLargest = array[i] } i++; }
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)
@Shaikh_zubair786 Жыл бұрын
Very useful Video 👍
@pawansinghrawat7886 Жыл бұрын
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);
@Lucky-po5ih Жыл бұрын
const arr=[1,5,-2,11,7] let res= arr.sort() console.log(res[arr.length-1])
@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 }
@cstej Жыл бұрын
/** Question Number 3 */ const input = [2,7, 11,4, -2]; function rotateArray(input, numOf){ for(let i=0; i
@pritamkeshri8389 Жыл бұрын
Awesome keep making such video
@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)
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 Жыл бұрын
Great. Can you share this solution.
@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 < 3) { 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 < n; 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 Жыл бұрын
@@ArunKumar-gx8iv Great Approach.
@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
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)
@nachiketdorkulkar7114 Жыл бұрын
Thanks sir for mock Interview
@harithati501 Жыл бұрын
please release as many videos as possible it would be helpful for us who are learning programming from youtube
@coderdost Жыл бұрын
yes trying that. will soon have more videos
@akshatsharma880 Жыл бұрын
Nice, It was a helpful video
@Webintelugu Жыл бұрын
let arr = [1,3,4,1,264,2311,2311,6]; let [max,secMax] = [-Infinity,-Infinity] for(let i = 0 ; i < arr.length;i++){ if(arr[i]>max){ secMax = max max = arr[i] }else if(arr[i]>secMax && arr[i] < max){ secMax = arr[i] } } console.log(secMax)
@praveen3794 Жыл бұрын
Subscribed🎉
@rakeshjha6492 Жыл бұрын
Really so helpful.
@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????
@muhammadumerfarooq31569 ай бұрын
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 }
@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 }
@AmitPandey_10 Жыл бұрын
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 Жыл бұрын
Very helpful 👍
@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);
@khaung441311 ай бұрын
You said he is a non CS-student but how does he know these algorithms though?
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 Жыл бұрын
@@coderdost Your KZbin shorts are very helpful, in real project.
@ankittyagi6706 Жыл бұрын
function sameProps(firstObj,secondObj){ let ans={}; for(item in firstObj){ if(firstObj[item]===secondObj[item]){ console.log(firstObj[item],secondObj[item]) ans ={...ans,[item]:firstObj[item]} } } return ans; } const input1={a:1,b:2,c:3,d:10,e:12} const input2={a:2,e:12,f:6,d:10} console.log(sameProps(input1,input2))
@susheelkumar62668 ай бұрын
He already used sort He has to just print length-2
@genius._bro Жыл бұрын
vscode text-editor are allow or not?
@a.spragadeeshbalaji291710 ай бұрын
const obj1 = {a:1,b:2,c:3,d:10,e:12}; const obj2 = {a:2,e:12,f:6,d:10}; let output = {}; for(let i=0; i
@pjgaming6695 Жыл бұрын
solved it in 15 seconds
@davidbaraiya2649 Жыл бұрын
How many years of experience this guy ?
@coderdost Жыл бұрын
Fresher non IT background
@mobpsycho6600 Жыл бұрын
Sir please make a video on how to do async operations in redux/toolkit
@coderdost Жыл бұрын
This will be covered in upcoming series of react JS. Thanks for suggestions.
@mobpsycho6600 Жыл бұрын
@@coderdost and one more thing please make it fully dependent on the redux 😁
@WorldSpace0074 ай бұрын
Sir can we use reverse function 3 times
@casull6447 Жыл бұрын
my answer for question 3: const input = [2, 7, 11, 4, -2]; function rotate(arr, num) { return [...arr.slice(num), ...arr.slice(0, num)]; } console.log(rotate(input, 2));