Data Structure and Algorithm Common Interview Questions (Part 2)

FizzBuzz, Array Chunk and Anagrams

fizzBuzz(5) output: 1,   2,   fizz,   4,   buzz

Solution

if(i % 3 === 0 && i % 5===0)

Array Chunk

chunk([1, 2, 3, 4], 2) --> [[ 1, 2], [3, 4]]chunk([1, 2, 3, 4, 5], 2) --> [[ 1, 2], [3, 4], [5]]chunk([1, 2, 3, 4, 5, 6, 7, 8], 3) --> [[ 1, 2, 3], [4, 5, 6], [7, 8]]chunk([1, 2, 3, 4, 5], 4) --> [[ 1, 2, 3, 4], [5]]chunk([1, 2, 3, 4, 5], 10) --> [[ 1, 2, 3, 4, 5]]

Solution

last.push(4) = [[1,4]]

Anagrams

anagrams('rail safety', 'fairy tales') --> Trueanagrams('RAIL! SAFETY!', 'fairy tales') --> Trueanagrams('Hi there', 'Bye there') --> False

Solution

The code

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store