JavaScript interview questions (Count Boomerangs In Array )

  Рет қаралды 1,033

itsCodingDoctor

itsCodingDoctor

Күн бұрын

Пікірлер: 18
@coder0015
@coder0015 2 жыл бұрын
Started learning JS recently. loved to watch this video, I literally want more of these!!
@itscodingdoctor
@itscodingdoctor 2 жыл бұрын
Great. You can find 23 more questions in this series
@g.pavani5275
@g.pavani5275 2 жыл бұрын
Very nice explanation bro it's really awesome ....waiting for regular videos to get uploaded in this interview series of JS
@itscodingdoctor
@itscodingdoctor 2 жыл бұрын
Thanks 😊
@nittasreenivas4043
@nittasreenivas4043 2 жыл бұрын
please solve this question alternating positive and negative number in js input:[9,4,-2,-1,5,0,-5,-3,2] output:[9,-2,4,-1,5,-5,0,-3,2]
@itscodingdoctor
@itscodingdoctor 2 жыл бұрын
Sure. Will create a video
@nitinsoni9956
@nitinsoni9956 2 жыл бұрын
At first the solution seems very simple but when I tried it damn it was tricky. Solved it by first finding indices of negative and positive numbers than using simple loop and finding the lower bounds length and upper bounds of respected arrays assigned the indices to new array and lasted compared which array is bigger and assigned remaining indices from that array.
@nitinsoni9956
@nitinsoni9956 2 жыл бұрын
let arr = [9, 4, -2, -1, 5, 0, -5, -3, 2,-2,2,3,3]; // pArr => positive indices nArr=> negative indices let pArr = arr.map((el, i) => (el >= 0 ? i : " ")).filter((el) => el !== " "); let nArr = arr.map((el, i) => (el < 0 ? i : " ")).filter((el) => el !== " "); // to store the new alternate numbers let alArr = []; // bb & lb => higher bound & lower as one of two arrays can be bigger hence we have to loop till bigger array length let bb = pArr.length > nArr.length ? pArr.length : nArr.length; let lb = pArr.length < nArr.length ? pArr.length : nArr.length; let pi=0,ni=0; for (let i = 0; i < bb; i++) { // as till lower bound both positive and negative indices array would have same number of elements if(lb > i){ alArr.push(arr[pArr[pi]]); alArr.push(arr[nArr[ni]]); pi++;ni++; } else{ // as positive array is bigger remaing numbers would be added from this array if(pArr.length > lb){ alArr.push(arr[pArr[pi]]); pi++; } // as negative array is bigger remaing numbers would be added from this array else{ alArr.push(arr[nArr[ni]]); ni++; } } } console.log(alArr);
@nittasreenivas4043
@nittasreenivas4043 2 жыл бұрын
@@nitinsoni9956 thankyou bro for helping out i just tried like this let arr = [9, 4, -2, -1, 5, 0, -5, -3, 2,-2,2,3,3] let positive = arr.filter((num) => { return num >= 0; }) let negative = arr.filter((num) => { return num < 0; }) let result = []; for(let i=0,j=0; i
@nitinsoni9956
@nitinsoni9956 2 жыл бұрын
@@nittasreenivas4043 You're welcome and there was always room for improvement in my code. I'm looking forward how codingDoctor solves the given problem.
@nitinsoni9956
@nitinsoni9956 2 жыл бұрын
I love this series but I guess the difficulty level was not hard as it was kind of easy question. I solved the question with the exact solution that was shown in the video.
@itscodingdoctor
@itscodingdoctor 2 жыл бұрын
Happy to hear that you could solve it yourself. It's a hard question though. But anyone having good knowledge of javascript can solve this.
@itscodingdoctor
@itscodingdoctor 2 жыл бұрын
I'll keep on increasing the difficultly level
@sakthiii711
@sakthiii711 2 жыл бұрын
Nice video for new topic bro, Please can you make video for [1,2,3,4,5] this will come to X pattern cross method .this was my interview question i don't know how to solve this problem.
@itscodingdoctor
@itscodingdoctor 2 жыл бұрын
Thanks
@itscodingdoctor
@itscodingdoctor 2 жыл бұрын
I couldn't understand this properly
@itscodingdoctor
@itscodingdoctor 2 жыл бұрын
Can you give me the input and expected output? I'll try to solve and create a video too
Увеличили моцареллу для @Lorenzo.bagnati
00:48
Кушать Хочу
Рет қаралды 8 МЛН
Players vs Pitch 🤯
00:26
LE FOOT EN VIDÉO
Рет қаралды 134 МЛН
ОДИН ДОМА! Когда уехали родители
18:49
SIDELNIKOVVV
Рет қаралды 763 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 835 М.
Dependency Injection, The Best Pattern
13:16
CodeAesthetic
Рет қаралды 883 М.