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.
@Its_Abhi_Thakur Жыл бұрын
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);
@coderdost Жыл бұрын
good and simple
@Its_Abhi_Thakur Жыл бұрын
@@coderdost thank you 😇
@ahmadraiyan1652 ай бұрын
let arr=[5,7,9,11,15,17] let arr2=[] for (let i = 0; i < arr.length; i++) { if ((arr[i]-arr[i-1])!==2&&(arr[i]-arr[i-1])==4) { arr2.push(arr[i-1]+2) } } console.log(arr2);
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);
@Rohit-zs7kn Жыл бұрын
const arr = [5, 7, 9, 11, 13, 15, 17, 21]; let index = 0; for (let oddNum = arr[0]; oddNum
@MehulJadavIndia Жыл бұрын
const input = [5, 7, 9, 11, 13, 15, 17, 21]; for (i = 0; i
@yesuraju-tf1yp Жыл бұрын
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
@itechinnovations2200 Жыл бұрын
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
@vin2368 Жыл бұрын
const Arr3 = [6,9,12,18,24,30] const n = 3 function getMissingOddNumbers(arr){ let output=[]; for(let i = 0;i
@AashMusic1 Жыл бұрын
const lst = [5, 7, 9, 11, 15, 17]; let res = [] for (let i =0 ; i < lst.length; i++){ let current = lst[i] let nextOdd = current + 2 if(lst[i+1]===nextOdd){ continue; }else{ res.push(nextOdd); break; } } console.log(res)
@werecodersАй бұрын
Very simple for (let index = 0; index < num.length; index++) { let current = num[index]; let next = current + 2; if (num.includes(next)) { continue; } else { console.log(next); break; } }
@abnow1998 Жыл бұрын
It is in AP(Arithmetic Progression) Just check Common Difference. Formula: a+(n-1)*d a is first number, d is common diff
@madhursangeet29 Жыл бұрын
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
@GurpreetSingh-gogsy Жыл бұрын
const input = [5,7,9,11,15,19]; for(let i=1;i
@ApurvaKashyap-kj6qz Жыл бұрын
Because binary search is applicable where we r given a target number to search in an array .. which is not in this case .
@PunkSage2 ай бұрын
Shortest I could think of: const i = [5,7,9,11,15,17]; const find = (a)=> { const f = (a[0] + a[a.length-1])/2*(a.length+1); const s = a.reduce((t, c)=> t+c, 0); return f-s; } console.log(find(i));
@AkashSingh-xf6bd Жыл бұрын
let input =[5,7,11,13,15,17]; let out = 13 function s(input){ for(let i= 0; i
@khanapeena21916 ай бұрын
in your code for loop should iterate till array.length-1
@tonmaysardar3331 Жыл бұрын
const input=[1,3,5,7,11,13,15,17] let b; for (let i=1;i
@syedwaseem37933 ай бұрын
function findMissingOddNumber(numbers) { // Loop through the array of numbers for (let i = 0; i < numbers.length - 1; i++) { // Check if the next number is not exactly 2 more than the current number if (numbers[i + 1] - numbers[i] !== 2) { // If not, the missing number is between these two numbers return numbers[i] + 2; } } // Return null if no number is missing return null; } const input = [5, 7, 9, 11, 15, 17]; const missingNumber = findMissingOddNumber(input); console.log(missingNumber); // Output: 13
@happylaughy2777 Жыл бұрын
const arr= [3,5,7,9,13] let odd=arr[0]; for(let i=0;i
@bathininaveen5198 Жыл бұрын
function findMissingOdd(arr){ for(let i =0;i 2) return arr[i] + 2; } return "No element is Missing!" }
@WalkingtotheTruth Жыл бұрын
Binary Search is possible here is the answer: function findMissingOddNumber (arr) { let left = 0 let right = arr.length - 1 let startingNumber = arr[0] let ans = -1 while (left
@Rubyd777 Жыл бұрын
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
@PunkSage2 ай бұрын
There is even a much simpler approach. Find my comment above.
@enthusiatic_coder6801 Жыл бұрын
const input = [5, 7, 9, 11, 13, 17, 19, 21]; const compare = (a, b) => { return a - b; }; for (let i = 0; i < input.length; i++) { // console.log(input[i]); if (input[i] - input[i + 1] !== -2) { console.log('The missing number is', input[i] + 2); input.push(input[i] + 2); input.sort(compare); break; } } console.log(input);
@yournanban38126 ай бұрын
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
@akkburf5450 Жыл бұрын
let arr = [5,7,9,11,15,17] function missNumber(arr){ for(let i =0 ; i < arr.length ; i++ ){ if(!(arr[i] + 2 === arr[i + 1])) return arr[i] + 2 } } console.log(missNumber(arr))
@prathamlashkari4230 Жыл бұрын
let input = [5, 7, 9, 11,15, 17]; for (let i = 0; i < input.length; i++) { let diff = input[i + 1]-input[i]; if (diff !== 2){ console.log(input[i]+2); break; } }
@niju7489 Жыл бұрын
//AP addition formula s= n/2(frst +last) let len = input.length ; return (input[0] +input[len-1])(len+1)/2 - input.reduce((a,c)=>a+c);
@mohammedrayyan30296 ай бұрын
const input7 = [5, 7, 9, 11, 15, 17, 21, 25]; const output7 = 13; function missingNumber(input7) { let index; for (index = 0; index < input7.length; index++) { if (input7[index] > output7) { break; } } input7.splice(index, 0, output7); return input7; } console.log(missingNumber(input7), "missing");
@abdulbasith65010 ай бұрын
let arr = [1,3,5,7,9,13] function misodd(arr){ let misnum; for(let i=0;i
@addep-kardy11 ай бұрын
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);
@chiraglegend2670 Жыл бұрын
function nextOdd(input){ for(let i=0 ; i < input.length ; i++){ let val = input[i]+2 if(val != input[i+1]){ return val } } }
@nitishgupta8393 Жыл бұрын
Q1: const missingOdd =(arr)=> { for(let i=0; i
@shazaibahmad78079 ай бұрын
Bro simple is that one if condition if(arr[I+1]-arr[I]===4) { return are[I+1]+2; } else{ return; }
@suryateja9881 Жыл бұрын
My solution for Sum 1: let input = [21,23,25,27,31,33,35,37,39,41,45,47,49,53]; for (let i=input[0];i
@YouTubeflixyt Жыл бұрын
Great quality content keep it up❤️
@nevilmistry740 Жыл бұрын
const arr = [3,5,7,9,11,13,17,19] //op -> 13 const arrLength = arr.length; let checker = 3 console.log(check(arr,arrLength,checker)) function check(arr,arrLength,checker){ for(i=0;i
@tejasshinde2011 Жыл бұрын
let temp =input[0]; for (let i = 0; i < input.length && input.includes(temp + 2); i++, temp += 2); console.log(temp + 2);
@maazhasan-mi8le Жыл бұрын
input.forEach((element,index)=>{ if (element + 2 !== input[index + 1] && input.length > index + 1) { console.log('missing number is ', element + 2) } } )
@akash_gupta_2090 Жыл бұрын
Missing odd numbers function missingFirstOddNumbers(arr) { const len = arr.length; let missingNumber = null; for (let i = 0; i < len; i++) { let _curr = arr[i]; let next = arr[i + 1]; if (next - _curr != 2) { missingNumber = _curr + 2; break; } } return missingNumber; }
@Doglapan64 Жыл бұрын
for (let i=0; i
@ankursharma1822 Жыл бұрын
let arr = [5,7,9,11,15,17]; for(value of arr){ let a = value +2; if(!arr.includes(a)){ console.log(a); break } }
Good logic. only thing use forEach in place of map. Map should only be used when array output is expected. Since map builds a new array, calling it without using the returned array is an anti-pattern. Reference : [developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map]
@rajatgour968611 ай бұрын
ok so let assume given arry is sorted const input = [5,7,9,11,15,17] let output = null for(let start = input[0]+2;start
@nevilmistry740 Жыл бұрын
2 nd answer const arr = [5,7,9,11,13,17,19] const arrLength = arr.length; let checker = 3 console.log(check(arr,arrLength,checker)) function check(arr,arrLength,checker){ for(i=1;i
@nevilmistry740 Жыл бұрын
just remove console😅😅😅
@40fps143 Жыл бұрын
for last question i thought of this -- console.log(input.map((el) => el *n))
@FreeTrial0315 Жыл бұрын
const arr =[5,7,9,11,15,17,19,23]; const data = new Set(arr) for(i=5; i
@ankitarya749211 ай бұрын
let arr = [1, 5, 7, 9, 11,13]; let j = arr[0]; for (let i = 0; i < arr.length; i++) { if (arr[i] !== j) { console.log(j) break } j+= 2 } KeepItSimple
@kiranm5419 Жыл бұрын
const input = [3,5,7,9,11,15,17]; for(let i=0;i
@unboxtheboxed-ox3cp Жыл бұрын
function oddcalc(arr){ for(let i=0;i2){ missing = (arr[i]+arr[i+1])/2; return missing; } } } let val =oddcalc([5, 7, 9, 11, 13, 15, 19]); console.log(val)
To change my algorithm to multiple of three, I have to increase the temp to 3.
@mohaimin95 Жыл бұрын
function missingOdd(arr) { for(let i = 1; i < arr.length; i++) { const last = arr[i - 1]; const current = arr[i]; if(current - last > 2) { return last + 2; } } }
@rahulkr7349 Жыл бұрын
the question was simple. not that hard but the interview makes your heartbeat sound like a banging drum.
const data = [5, 7, 11, 15, 17] for(let i =data[0]; i
@Snagesh3770 Жыл бұрын
const input = [5, 7, 9, 11, 15, 17]; function missingOddNumbers(arr) { let min = Math.min(...arr); let max = Math.max(...arr); let oddNumbers = []; for (let i = min; i !arr.includes(x)); return res } console.log(missingOddNumbers(input));
@NavneetTaneja-d1y Жыл бұрын
easy first sort then extract min and max after than loop range from min to max than extrat odd number list that number not in arr that is missing after first missing get break the array
@FarhanKhan-ox4iy Жыл бұрын
I see in the comments no one has used two pointers for this. With that we can achieve linear time complexity. Use start and end. Run while loop until end >= start. start++ and end--
@PunkSage2 ай бұрын
No reason to use it here. All you need to do is to calculate the sum of numbers.
@darklord9500 Жыл бұрын
function findMissingNumber(arr) { let missingNumber = null; for (let i = 0; i < arr.length; i++) { if (arr[i] !== arr[0] + i * 2) { missingNumber = arr[0] + i * 2; break; } } return missingNumber; }
@teentexh Жыл бұрын
let array=[5,7,9,11,15,17]; let value=array[0]; for(let a of array){ if(a===value){ value+=2 ; }else{ console.log(value); break; } }
@stefumies3 ай бұрын
const missingNumber = input.reduce((ac,c,i,a) => i == 0 ? a : ((c - a[i-1])> 2) ? a[i-1] + 2 : ac ,null)
@sannisinha58 Жыл бұрын
It's very helpful... please continue😊
@AbdurRahimKhan-gz1jo Жыл бұрын
Hey, @coderdost please do more videos like this...
@coffee0919 Жыл бұрын
function findOdd(arr) { for (let i = 0; i < arr.length; i++) { if (arr[i] + 2 !== arr[i + 1]) { return arr[i] + 2; } } return -1; } Is that work?
@brainnbeyond Жыл бұрын
what I had done for(let i=0; i< input.length; i++){ if(input[i+1] - input [i] > 2){ console.log(input[i] + 2) } } is it right ?
@coderdost Жыл бұрын
yes. replacing 2 by "n" can make it more dynamic to and useful fo any kind Arithmetic progression
@laylahashmi4234 Жыл бұрын
function missingOddNum(arr) { let completeArr = [arr[0]]; for (let i = 0; i < arr.length; i++) { let value = completeArr[i] + 2; completeArr.push(value) } return completeArr.filter((num) => !arr.includes(num)) }
@584_tyit_rohitghadge93 ай бұрын
let arr=[1,3,9,11,15,17]; let emp=[]; let missingvalue=(arr)=>{ let min=Math.min(...arr); let max=Math.max(...arr); for(let i=min;i
@zimbasardhara3450 Жыл бұрын
let data =[1,3,5,7,9,11,15,17,19,21] let data2=[]; for(let i=0;i
@harshjoshi6496 Жыл бұрын
@coderdost Binary search is possible here, Solution: (Explanation at last) const input = [5, 7, 9, 11, 15, 17,19, 21]; first = 0 last = input.length-1 mid = (first+last)/2 while (first
@coderdost Жыл бұрын
nice exaplanation
@sanvijha Жыл бұрын
We can not apply binary search for this problem as we have to evaluate key from the array itself.
@arbazhussain6751 Жыл бұрын
Sir, I have tried to solve this question. Is it correct? // find the first missing ODD number let input = [5,7,9,11,15,17]; for(let i = input[0]; i < input[input.length-1]; i++){ if(i % 2 !== 0){ if(!input.includes(i)){ console.log(i); break; } } }
@coderdost Жыл бұрын
Even though it works. But there are some unnecessary iterations like "i" is 5,6,7,8,9 etc.. these values are not all needed like 6, 8 , 10 etc. You can optimize this solution to a more simpler method.
@rajatraj3160 Жыл бұрын
sort the array use map and return the element which which has remainder 1. Or u can use sort along with map
@coderdost Жыл бұрын
@@rajatraj3160 array is already sorted.. so its even simpler now. and we can't evaluate using remainder, as here all numbers are ODD only. problem is to find out 1 missing number from sequence.
@AbhishekKumar-xw1cm Жыл бұрын
see this let input = [5,7,9,11,15,17] let n = 2 const findMissing = (input,n) => { for(let i =0 ; i < input.length ;i++){ if(input[i]+n !== input[i+1]){ return input[i]+n } } } console.log(findMissing(input,n))
@uditkhandelwal63305 ай бұрын
USING BINARY SEARCH -> const input1 = [5, 7, 11, 13, 15, 17, 19]; const input2 = [19, 17, 13, 11, 9, 7, 5]; const findMissingOddNumber = (arr) => { let l = 0; let r = arr.length - 1; let d; if(arr[l]
@sumitkumar-in2si Жыл бұрын
Is this correct? let input=[5,7,9,11,15,17]; for(let i=0;i
@coderdost Жыл бұрын
Yes
@rahil516 Жыл бұрын
First view ; Sir your videos are very helpful appreciated
@nikhilnikki9627 Жыл бұрын
IS THIS CORRECT WAY: const input=[5,7,9,11,15,17] let first =input[0] for (let i of input){ if (i ===first){ let next = first+2 first=next } else{ console.log(first) } }
@coderdost Жыл бұрын
yes, but I think you can remove "first" and use only 1 variable "next" let next =input[0] for (let i of input){ if (i ===next){ let next = next+2 } else{ console.log(next) } }
@Doglapan64 Жыл бұрын
@coderDost Please let us know how to break forEach loop ? without using try-catch
@a.spragadeeshbalaji291710 ай бұрын
//FIND THE MISSING ODD NUMBER WITHIN THE RANGE SPECIFIED IN THE ARRAY const input = [5,7,9,11,15,17]; for(let i=input[0]; i
@namangaur5329 Жыл бұрын
Binary search is not helpful in this case bcz in binary search we find a given number within array. But here the number itself not determined. So first we need to find the number and then we can use the bs to find the appropriate position for the number. I'm hoping that the answer is correct..😅 But this type of content is really helpful for us ... Thank u sir for making such type of content❣️
@coderdost Жыл бұрын
True story
@WalkingtotheTruth Жыл бұрын
Binary Search is possible here is the answer: function findMissingOddNumber (arr) { let left = 0 let right = arr.length - 1 let startingNumber = arr[0] let ans = -1 while (left
@WalkingtotheTruth Жыл бұрын
@@pawansinghrawat7886 const mid = Math.floor((left + right) / 2) this is the mid,we are traversing logn times not whole array,you can run this code and anlysis yourself, thank you.
@notyournormaldev1419 Жыл бұрын
yes it is possible, i am the one in this video@@WalkingtotheTruth
@payalkothari4862 Жыл бұрын
let missingNumber; for (let i = input[0]; i
@lalitsinghnegi1562 Жыл бұрын
aaj meri joining thi or m MERN stack profile ke liye gya tha or saalo ne python ( flask ) ka project de dia ... pehle se bna hua tha ab usme new functionalities dd krni h or mujhe python aati h nhi .. ab m kya kru
@coderdost Жыл бұрын
I think learn python because JS and python are almost same. and flask is much easier like express kzbin.info/www/bejne/Z3yWq62lpK98gK8
@lalitsinghnegi1562 Жыл бұрын
@coderdost aap shi keh rhe h but agr wo pehle ye baat bta dete ya post m mentioned kr dete to m join hi nhi krta .. but ab bna hua project h to mere kch samjh m aa nhi rha h .. smjh nhi aara kya kru
@coderdost Жыл бұрын
There are some hard realities of tech sector...they hire for some profile but give work in some other...specially to freshers.. Its hard to judge many companies..
@lalitsinghnegi1562 Жыл бұрын
@coderdost yes bro .. i think i should quit ...
@coderdost Жыл бұрын
In sab facts ko batane k liye ek alag channel banane ka socha h ... soon will plan.. code wale channel pe to mix nhi krenge
@jsview5315 Жыл бұрын
Hi sir I am fresher Frontend dev i have completed projects and portfolio too and have little bit DSA knowledge but Machine coding and this type question se daar lgta hai so job ki tention aa rahi hai . Please suggest anything
@coderdost Жыл бұрын
Everyone fears such questions as they are matter of practice. So just keep doing such questions more and more. And in real round they will feel simpler. Without practice it will be hard
@jsview5315 Жыл бұрын
@@coderdost Thanks for the reply sir your content is awesome.
@AvadheshVerma24 Жыл бұрын
for (let i = 0; i < arr.length; i++) { let c = arr[i]; let next = c + 2; if (!arr.includes(next)) { console.log(next); break; } }
@ankurpandey3152 Жыл бұрын
Wow nice interview
@nileshnilu7902 Жыл бұрын
Make more video like this very her.
@immdipu Жыл бұрын
function missingOdd(array){ let firstDigit = array[0]; let missingDigit = null; while(missingDigit === null){ if(firstDigit % 2 !== 0){ if(!array.includes(firstDigit)){ missingDigit = firstDigit; return missingDigit; } } firstDigit++; }
@coderdost Жыл бұрын
Why we will need to check -> firstDigit %2, as all are odd only. and will have mod as 1.
@immdipu Жыл бұрын
@@coderdost all are not odd. firstDigit will increase by one each time the while loop runs. so it means the first time while loop runs firstDigit will be 5 and second time the while loop run the value of firstDigit will increase by one i.e 6 . 6 is not a odd number so that why we need firstDigit%2
@coderdost Жыл бұрын
@@immdipu OK, I think you can optimize by reducing the iteration and skipping the even increments totally
@AbhishekSharma-fg1ho Жыл бұрын
its front end dev interview?? and which type of qus asking in front end dev
@coderdost Жыл бұрын
its only coding round for javascript (front-end). which is not compulsory in all companies Some other interview playlists: REACT Interview Shorts : bit.ly/3VfIrMi JAVASCRIPT Interview Shorts: bit.ly/3XhHRQ1 More REACT video Interviews - bit.ly/3QAjAln
@DhirajkaReview26 Жыл бұрын
Sir one question currently i am cdac student they teaches so many concepts rapidly and some topics I don't understand so can u tell me about is that our interview is which base and how should I have to prepare for interview the level Interview they can u tell me about that ??
@coderdost Жыл бұрын
for long term only your knowledge matter, how many projects you have worked on. What you can make. preparing for interview is only a short term things for placements. Interviews are mostly based on popular tricky questions. Just go on internet and check the question related to JS or React. Same 50 questions are asked mostly We made a playlist of popular question in JS and React here : REACT Interview Shorts : bit.ly/3VfIrMi JAVASCRIPT Interview Shorts: bit.ly/3XhHRQ1
@DhirajkaReview26 Жыл бұрын
@@coderdost thanks sir , i saved those playlist and sir one more thing as knowledge perspective my explanation and understanding is good but sometimes I can't write because of syntax is that ok ? As i herad from student interview just how much i understand and even if writte normal code they say is ok for them to hire , like now they start adv java as seen jdbc code to connect i don't they will write that whole code in 1 hour interview can tell me about those things , i have your adv java one video also for reference 🤓 can explain this point how much interview can ask like 5 min code on notepad ?
@coderdost Жыл бұрын
@@DhirajkaReview26 Most of them look for approach rather than exact code. So your code or Pseudocode should explain the steps. They look if you can think of logic, why this logic, what are limitation of that logic, are their any bounds in which that logic will work, are there performance issue with that logic,... They try to change some part of that question also - to check if you can now think of different logic also, to check if you have not mugged up from somewhere. If they have to check syntax and code prefection they will always ask to code on some machine.
@DhirajkaReview26 Жыл бұрын
@@coderdost thank u so much to clear my questions, getting proper suggestions and knowledge From u it's so much for me , thanks lot 🙏
@pritamkeshri8389 Жыл бұрын
// ===========Missing odd Number const arr5 = [5, 7, 9, 11, 15, 17]; const arr5output = 13; function findOddNumber(input) { let output; for (let i = 0; i < input.length; i++) { let current = input[i]; let future = input[i + 1]; if (future && future - current !== 2) { output = current + 2; } } return output; } console.log(findOddNumber(arr5));
@mitesh5189 Жыл бұрын
const b = [5,7,11,13,17] function missOdd(arr) { let i = arr[0]; let a =0 while(true){ if(arr[a]===i){ i +=2; a++; } else{ console.log(i); break; } } } missOdd(b);
@coderdost Жыл бұрын
simple and effective. using 'a' as index and 'i' as element is only distracting part.
@DeepakGupta-yk2ep Жыл бұрын
Sir please make more Javascript interview videos
@coderdost Жыл бұрын
Yes 👍🏻
@gojo55x Жыл бұрын
Can you please tell me sir how much experience he has.....
@coderdost Жыл бұрын
Fresher
@nazirrizwan Жыл бұрын
Sir how apply and what procedure to all about this interview
@coderdost Жыл бұрын
There is a form which was put on community tab. Or directly book slot via emailing us. Email is in about us section. Business email section
@PIYUSH-lz1zq Жыл бұрын
Bro , coding rounds ks ek alag se playlist bana do !!!
@coderdost Жыл бұрын
Will do
@PIYUSH-lz1zq Жыл бұрын
@@coderdost u uploaded only 2 video on js coding round ??
@coderdost Жыл бұрын
@@PIYUSH-lz1zq 3 videos. all in react interview playlist right now.. will move to separate one
@AkashSingh-xf6bd Жыл бұрын
Coder Dost, Hi I did not get you "n" concept in last can you explain me
@coderdost Жыл бұрын
like here N was 2. as each next number was +2. So just asked if we can code for any AP series like 3,6,9 - where N=3 and so on.
@AkashSingh-xf6bd Жыл бұрын
@@coderdost okay, now I get this
@montugohain48 Жыл бұрын
Great video ,really helpful, I also tried is to solve and came up with this one.. class ArithmeticProgression { arr = []; constructor(a, n, num) { for (let i = 0; i < num; i++) { this.arr.push(a + n * i); } } AP_generator() { return this.arr; } AP_sum() { return this.arr.reduce((acc, cur) => acc + cur); } } const input = [5, 7, 9, 11, 15, 17]; const CompleteAP = new ArithmeticProgression( input[0], input[1] - input[0], ++input.length ); const givenTotal = input.reduce((acc, cur) => acc + cur); const ans = CompleteAP.AP_sum() - givenTotal; console.log(ans);
@coderdost Жыл бұрын
Answer might be right. But its a complicated approach also uses a lot of operations of summing whole array twice etc. both space and time complexity becomes high
@CryptoAirdropnow Жыл бұрын
is there any way to give a mock interview with you
@coderdost Жыл бұрын
you can email. at email given on about page.
@kiranm5419 Жыл бұрын
const input = [5,7,9,11,15,17]; const a = []; const b = []; for(let i=0;i
@rajulorencemurmu3838 Жыл бұрын
My approach is:- Since they all are odd then what we can do is create an array and store all odd elements in that array like 5 to 17 then we can compare them both using loops if the first element of new array does not match to the first element of previous array then we print that.
@coderdost Жыл бұрын
but creating another array is extra effort. it will increase the space complexity. you can use same logic on original array and check if next element is not the next Odd number ( previous + 2)