Top 10 Javascript Algorithms to Prepare for Coding Interviews

Поділитися
Вставка
  • Опубліковано 21 гру 2024

КОМЕНТАРІ • 82

  • @CodingMoney
    @CodingMoney 9 місяців тому +31

    1:00 Reverse String & Integers
    11:29 Palindrome
    15:58 Max Char
    33:43 Array Chunking
    41:56 Title Case
    49:31 Anagrams
    1:07:54 Count Vowels
    1:15:21 Fizz Buzz
    1:20:02 Steps String Pattern
    1:30:52 Pyramid String Pattern
    1:39:24 Bonus - Spiral Matrix

    • @euroclydon7883
      @euroclydon7883 5 місяців тому

      const palindromeWithTwoPointers = (str: string) => {
      let left = 0;
      let right = str.length - 1;
      while (left < right) {
      if (str[left] !== str[right]) {
      return false;
      }
      left++;
      right--;
      }
      return true;
      };

  • @sayedrezaomid1305
    @sayedrezaomid1305 9 місяців тому +13

    I am very happy that i saw my Afghan and ex colleaque trainings at this channel.

  • @augustoeduardo209
    @augustoeduardo209 9 місяців тому +19

    Beatiful countryside landscape.

  • @atultrp1
    @atultrp1 9 місяців тому +6

    // every method
    function palindrome(str) {
    return str.split('').every((ele, i) => {
    return ele == str[str.length - i - 1]
    })
    }
    // two pointer technique
    function palindrome2(str) {
    let start = 0
    let last = str.length - 1
    while (start < last) {
    if (str[start] != str[last]) {
    return false
    }
    else {
    start++
    last--
    }
    }
    return true
    }

    • @Emblazon
      @Emblazon 4 місяці тому

      yea, using two pointers is faster

  • @MyCodingDiary
    @MyCodingDiary 9 місяців тому +3

    You're changing lives with your content. Keep inspiring!

  • @daisy_haniii
    @daisy_haniii 8 місяців тому +3

    Palindrome using two pointers technique:
    function isPalindrome(str) {
    let min = 0
    let max = str.length - 1
    do {
    if(str[min] == str[max]) {
    min++
    max--
    } else {
    return false
    }
    }while(min < max)

    return true
    }

    • @mahmoudzakria6946
      @mahmoudzakria6946 5 місяців тому

      function palindrome(str){
      return str === [...str].reverse().join("")
      }

  • @lavendercode
    @lavendercode 9 місяців тому +4

    Awesome video! Thank you for making it 😀

  • @WhitneyChakara
    @WhitneyChakara 9 місяців тому +3

    This is excellent and able to be completed as it's short and straight to the point.

  • @sergeynazarov2473
    @sergeynazarov2473 9 місяців тому +1

    Perfect, trainees will be ready!

  • @MrMouniruss
    @MrMouniruss 18 днів тому

    Hi,
    For the MaxChar you can do this way :
    function maxChar(str){
    let arr = str.split("");
    let maxChar = "";
    arr.forEach(element => {
    if(arr.filter(el => el === element).length > maxChar.length) {
    maxChar = element;
    }
    });
    return maxChar;
    }

  • @khanhphamthanh5012
    @khanhphamthanh5012 9 місяців тому +4

    amazing spiral Matrix. It really so hard for me to find out the way. Thank you for your code

  • @narekmeliksetyan01
    @narekmeliksetyan01 9 місяців тому +3

    it was very useful. but I will suggest the following solution for problem 9.
    function foo(n){
    for(i=1;i

    • @vnm_8945
      @vnm_8945 8 місяців тому

      You could just use Array(i) instead of Array.from({length:i}), nice solution!

  • @Website_TV_1
    @Website_TV_1 2 місяці тому

    Awesome breakdown of key algorithms! 🎉 Definitely a must-watch for anyone preparing for coding interviews. Loved how clearly each algorithm was explained, especially the time complexities and practical examples. 💻 Thanks for making these tough concepts easier to grasp! 🙌

  • @andrewwall2730
    @andrewwall2730 2 місяці тому

    Very informative. Thanks so much for sharing. Though there is a simpler solution for #9, steps:
    const steps = n => {
    for (let i = 1; i

  • @nazardzys7514
    @nazardzys7514 7 місяців тому

    Hi, thanks for your video!
    On example 5 you can also use Array.splice() method. I believe, it looks more cleaner comparing to solution with Array.slice().
    here's the whole solution:
    return str
    .split(" ")
    .map((item) => {
    const word = item.split("");
    word.splice(0, 1, word[0].toUpperCase());
    return word.join("");
    })
    .join(" ");
    }

  • @savchenkoilliya9131
    @savchenkoilliya9131 9 місяців тому +1

    In my opinion I can give better and more javascript-style solutions for at least couple tasks. Maybe it's a little bit harder to read, but it works better when we are talking about js:
    var chunk = (array, size) =>
    (array.length (str.split(" ")
    .map((word)=>
    (word.charAt(0).toUpperCase() + word.slice(1)).join(" ")))
    P.S.
    Good practice show O(n) complexity for each solution, because it's a think that can be asked on any interview.

  • @mr_aha4713
    @mr_aha4713 9 місяців тому

    12:23
    function pal(str){
    console.log(str)
    if (str === str.split('').reverse().join('')){
    return true
    }else {
    return false
    }
    }
    console.log(pal(""))

  • @arzoohashimi519
    @arzoohashimi519 9 місяців тому +4

    Very informative and helpful.

  • @edwarddk9007
    @edwarddk9007 7 місяців тому

    my solution for the Pyramid String Pattern exercise: function pyramid(n, level, body, space) {
    if(level

  • @Mayur-w6v
    @Mayur-w6v 9 місяців тому

    Q1:
    function reverseIt(str){
    let newArr = '';
    for(let i = 0; i< str.length ; i ++)
    {
    newArr += str[str.length -i-1];
    }
    return newArr;
    }
    console.log(reverseIt('hello'))

  • @Asifpatel-b8o
    @Asifpatel-b8o 9 місяців тому +2

    So engaging and interesting thank you sir for this lecture ❤

  • @MBXD001
    @MBXD001 4 місяці тому +1

    so just with these, are we going to be able to complete the legacy js data structures algorithms certification on freecodecamp ?

  • @kalechips965
    @kalechips965 9 місяців тому

    These are way easier than "easy" leetcode problems.

  • @LokeshKumar-tk7ri
    @LokeshKumar-tk7ri 9 місяців тому

    Thank you Free code Camp for providing DSA in Javascript and also need more content on JS DSA

  • @marioerichsen1977
    @marioerichsen1977 8 місяців тому +2

    function palindrome(str) {
    //with two pointer technique
    var stringArr = str.split('')
    const reverseArray = (arr) => {
    let i = 0;
    let j = arr.length-1;
    while (i < j) {
    let tmp = arr[i];
    arr[i++] = arr[j];
    arr[j--] = tmp;
    };
    return arr
    };
    const reversed = reverseArray(stringArr)
    return str === stringArr.join('')
    }

  • @Website_TV_1
    @Website_TV_1 2 місяці тому

    it was very useful, help me a lots for the interview

  • @senthamarai_kannan.
    @senthamarai_kannan. 6 місяців тому

    function steps(num){
    for(let i= 0; i < num; i++){
    let str = '' "
    for(let j=0; j

  • @-.nisa.-
    @-.nisa.- 9 місяців тому

    1:39:20 This is such an overcomplication... One 'for' loop is more than enough here:
    for (let i = 1; i

    • @arzoohashimi519
      @arzoohashimi519 9 місяців тому

      Big o notation for repeat function is o(n) which is similar to a for loop. So ur solution is also the same.

  • @DavidMorenoH
    @DavidMorenoH 9 місяців тому +7

    OMG please do this but with Java or Python

    • @abdo01386
      @abdo01386 9 місяців тому

      Ther is ful apk in webstores

  • @Aso-c6z
    @Aso-c6z 9 місяців тому +2

    Love this video ❤

  • @ajiteshmishra0005
    @ajiteshmishra0005 7 місяців тому

    We want more videos on these String and Array manipulation methods and programming questions

  • @lazarokabira2945
    @lazarokabira2945 9 місяців тому +3

    Love this

  • @shulamohammad2275
    @shulamohammad2275 9 місяців тому

    loved the tutorial by Mukhtar!

  • @Adolfofilipe7369
    @Adolfofilipe7369 9 місяців тому +1

    Thanks for your help 🎉🎉🎉🎉🎉🎉

  • @murshidalam1982
    @murshidalam1982 9 місяців тому +1

    Very helpful.

  • @ManiSingh-gr7zi
    @ManiSingh-gr7zi 6 місяців тому

    Excellent, thank you.

  • @FULLUPE1
    @FULLUPE1 5 місяців тому

    great and awesome thanks sir but with steps this is a little modification const (no if and else)
    steps=(n)=>{
    for (let i=1; i

  • @gauthamchengappa1702
    @gauthamchengappa1702 3 місяці тому

    Palidorme soluton - 2 pointer method
    function checkPalidrome2PointerMethod(str) {
    let left = 0;
    let right = str.length - 1;
    while (left < right) {
    if (str[left] !== str[right]) {
    return 'Not a palidrome'
    }
    left++;
    right--;
    }
    return 'It is a palidrome'
    }

  • @dudekool12
    @dudekool12 9 місяців тому

    Need this in Python!

  • @МарияЕфимова-ч4б
    @МарияЕфимова-ч4б 8 місяців тому

    function isPolindrom(str) {
    let check = str.split('').reverse().join('');
    return str === check ? true : false
    }

  • @ajiteshmishra0005
    @ajiteshmishra0005 7 місяців тому

    We are learning well from these type of Videos
    But please zoom in something more so that we can see the screen properly.

  • @Emblazon
    @Emblazon 4 місяці тому

    idk if it is "cheating", but my solution for the steps makes use of recursion
    function steps(n, i = 0, s = "") {
    if (i > n) return;
    s = "#".repeat(i);
    console.log(s);
    steps(n, ++i, s);
    }
    steps(7);

  • @loaymohamed8134
    @loaymohamed8134 4 місяці тому

    My solution for Spiral Matrix
    const spiral = (num) => {
    const matrix = Array.from({length: num}, ()=>Array(num).fill(0)) // n*n matrix filled with 0's
    let i=0, j=0;
    let count = 0;
    matrix[i][j]=++count;
    while(count

  • @ajmalshahanpm938
    @ajmalshahanpm938 9 місяців тому

    function count(str){
    let counter=0;
    // for(let i=0;ifi===str[i])) {
    // counter++;
    // }
    // }
    for(single of str){
    if (['a','i','o','e','u'].some((fi)=>fi===single)) {
    counter++;
    }
    }
    return counter;
    }
    console.log(count("aj code"));

  • @giftedfingers2580
    @giftedfingers2580 7 місяців тому

    I'm having a hard time understanding what part of the reverse function is the actual part doing the reversing can someone please clarify...

  • @MS-gi3hc
    @MS-gi3hc 9 місяців тому

    Thank you

  • @alikh5601
    @alikh5601 9 місяців тому +3

    Saved

  • @Spartan-v1i
    @Spartan-v1i 3 місяці тому

    Sir make full course about game developement and javascript full dsa video

  • @MBXD001
    @MBXD001 4 місяці тому

    so after this we can go to leetcode and start grinding ?

  • @ITRebels
    @ITRebels 8 місяців тому

    awesome

  • @SaeedITSpot
    @SaeedITSpot 9 місяців тому

    🎉🎉🎉

  • @МарияЕфимова-ч4б
    @МарияЕфимова-ч4б 8 місяців тому

    function checkVowels(str) {
    let arr = []
    const vowelsArray = ['a', 'e', 'i', 'o', 'u']
    let arrFrStr = str.toLowerCase().split('')
    for (let i of vowelsArray) {
    for (let y of arrFrStr) {
    if (i === y) {
    arr.push(i)
    }
    }
    }
    return arr.length
    }

  • @vijayakabajo
    @vijayakabajo 9 місяців тому

    0:22 He owns a farm

  • @m0slah
    @m0slah 9 місяців тому +3

  • @moshtabamorsali
    @moshtabamorsali 7 місяців тому

    I did each of them in a different way but still working in the same performance😶‍🌫

  • @rishiraj2548
    @rishiraj2548 9 місяців тому +3

    👍🙂👍

  • @asilvap
    @asilvap 9 місяців тому

    Honestly, any companies could ask questions like these?

  • @DavidDroddy
    @DavidDroddy 8 місяців тому

    For String and Int reversal and Palindrome -- .every and two pointer techniques:
    // STRING.SPLIT INTO ARRAY
    //const reverseString = (theString) => theString.split('').reverse().join('');
    // SPREAD STRING(ARRAY-OF-CHARACTERS) INTO ARRAY
    // const reverseString = (theString) => [...theString].reverse().join('');
    // ARRAY.EVERY(element, index, array)
    const reverseString = (theString) => {
    let reversedString = '';
    const reversiosa = (character, i, charArray) => {
    // using index and array (all tests pass)
    // let lastElement = charArray[charArray.length - ++i];
    // return reversedString += lastElement;
    const j = charArray.length - (++i)
    return reversedString += charArray[j];
    // using element (all tests pass)
    // return reversedString = character + reversedString;
    };
    [...theString].every(reversiosa)
    return reversedString;
    }
    // "TWO POINTER" SOLUTION
    // const reverseString = (theString) => {
    // let i = 0;
    // let j = theString.length-1;
    // let stringArray = [...theString];
    // while(i parseInt(reverseString(theNumber.toString())) * Math.sign(theNumber);
    const isPalindrome = (theString) => reverseString(theString) === theString;
    // TESTS
    const stringToReverse = 'jar';
    const expectedReversedString = 'raj';
    const reversedString = reverseString(stringToReverse);
    let expectedAndReceived = `expected: ${expectedReversedString}; received: ${reversedString}`;
    if(reversedString === expectedReversedString) {
    console.log(`pass - reverseString('${stringToReverse}')
    ${expectedAndReceived}`);
    } else {
    console.error(`FAIL - reverseString('${stringToReverse}')
    ${expectedAndReceived}`);
    }
    let intToReverse = 53;
    let expectedReversedInt = 35;
    let reversedInt = reverseInt(intToReverse);
    expectedAndReceived = `expected: ${expectedReversedInt}; received: ${reversedInt};`;
    if(reversedInt === expectedReversedInt){
    console.log(`pass - reverse a POSITIVE integer
    reverseInt(${intToReverse})
    ${expectedAndReceived}`);
    } else {
    console.error(`FAIL - reverse a POSITIVE integer
    reverseInt(${intToReverse})
    ${expectedAndReceived}`);
    }
    intToReverse = -54;
    expectedReversedInt = -45;
    reversedInt = reverseInt(intToReverse);
    expectedAndReceived = `expected: ${expectedReversedInt}; received: ${reversedInt};`;
    if(reversedInt === expectedReversedInt){
    console.log(`pass - reverse a NEGATIVE integer
    reverseInt(${intToReverse})
    ${expectedAndReceived}`);
    } else {
    console.error(`FAIL - reverse a NEGATIVE integer
    reverseInt(${intToReverse})
    ${expectedAndReceived}`);
    }

  • @euroclydon7883
    @euroclydon7883 5 місяців тому

    const palindromeWithTwoPointers = (str: string) => {
    let left = 0;
    let right = str.length - 1;
    while (left < right) {
    if (str[left] !== str[right]) {
    return false;
    }
    left++;
    right--;
    }
    return true;
    };

  • @MBXD001
    @MBXD001 2 місяці тому

    Your solution for titleCase will not work if there is a character that is already uppercase so
    ArrayChunking solution and TitleCase Solution
    function titleCase(str) {
    return str.toLowerCase().split(' ').map(char=>char[0].toUpperCase() + char.slice(1)).join(' ')
    }
    function chunk(array, size){
    let arr = [ ]
    for(let i =0;i

  • @ajiteshmishra0005
    @ajiteshmishra0005 7 місяців тому

    for(var i = 1; i {
    console.log(i);
    }, 1200);
    }
    Output is
    4
    4
    4
    &
    for(let i = 1; i {
    console.log(i);
    }, 1200);
    }
    Output is
    1
    2
    3
    Why??

    • @giftedfingers2580
      @giftedfingers2580 7 місяців тому

      The for loop is using var which in turn the compiler recognizes the var but not its value. Second, the setTimeout has an arrow function and that creates a closure.

  • @phyapanchakpram
    @phyapanchakpram 8 місяців тому

    //alternate newbie solution
    function capitilizeFirstLetter(str) {
    let arr = str.split(' ');
    let result = [];
    for(let s of arr) {
    result.push(s.charAt(0).toUpperCase() + s.substr(1))
    }
    return result.toString().replace(/,/g,' ');
    }

  • @HazimTulumovic
    @HazimTulumovic 7 місяців тому

    Max chars:
    function maxChar(str) {
    const usedChars = {};
    for (const char of str) {
    usedChars[char] = usedChars[char] ? usedChars[char] + 1 : 1;
    }
    return Object.keys(usedChars).sort((a, b) => usedChars[b] - usedChars[a])[0];
    }

  • @phyapanchakpram
    @phyapanchakpram 8 місяців тому

    //To return all char if max occurence has more than one time
    function maxOccurence(str) {
    let charMap = {};
    for(let char of str) {
    charMap[char] = (charMap[char] || 0) + 1;
    }
    let max = 0;
    let maxChar = [];
    for(let key in charMap) {
    if(charMap[key] > max){
    max = charMap[key];
    }
    }
    for(let char in charMap) {
    if(charMap[char] === max) {
    maxChar.push(char);
    }
    }
    return maxChar;
    }

  • @subashstino899
    @subashstino899 9 місяців тому

    Is this MERN Stack developer needs to Study DSA ???… And I want to know Any best book for DSA( Data structure and algorithms )……????

    • @feerfeja
      @feerfeja 9 місяців тому

      this video course is the best for learning algorithms in Javascript :p

  • @Akintomidevictor-nx8xf
    @Akintomidevictor-nx8xf 3 місяці тому

    Dear Instructor
    I hope you're doing well. I'm Victor, a student in your Machine Learning Model Deployment with Stream lit
    class.
    I’m reaching out for some clarification on [Machine Learning Model Deployment with Stream lit],
    as I’m having difficulty understanding certain parts. Could you
    please provide further guidance or suggest additional resources? If
    possible, I’d appreciate a brief meeting during your office hours.
    Thank you for your time and help! Best regards, Victor,

  • @dogukankarabeyin3059
    @dogukankarabeyin3059 8 місяців тому

    Guys these questions and answers are identical to Stephen Grider's Coding Interview Bootcamp udemy course. I get these are common questions but it just seemed too similar.

  • @nicolasmanns7249
    @nicolasmanns7249 8 місяців тому

    Palindrome with some kind of two pointers made with a for loop (also removes caps and spaces)
    function palindrome(str) {
    strToTest = str.toLowerCase().split(" ").join("");
    let isPalindrome = true;
    for (let i = 0; i

  • @OthmaneAHMARLAHYA
    @OthmaneAHMARLAHYA 9 місяців тому +2

    i'm sure no one understand this

  • @HazimTulumovic
    @HazimTulumovic 7 місяців тому

    Max chars :
    function maxChar(str) {
    const usedChars = {};
    for (const char of str) {
    usedChars[char] = usedChars[char] ? usedChars[char] + 1 : 1;
    }
    return Object.keys(usedChars).sort((a, b) => usedChars[b] - usedChars[a])[0];
    }