Top Programming Interview Questions and Answers. Part — 1
Hello, I decided to share my Repl.it and Gist repositories, about the programming/development specific questions and answers.
In this post, I’m diving into the Strings and Arrays using Javascript.
So, let’s get started.
Counting number of vowels in a string
You can actually do this with a small regex.
Recursively print all permutations of a string
Let’s write a function that returns all permutations of a string as an array. As you don’t want any global variables, returning the permutations is crucial.
Anagram comparison
Instead of comparing letter by letter, after sorting you can join the arrays to strings again.
How do get the second largest element from an array
The most straightforward implementation, without modifying the original array
Find the smallest and largest value in an array
The easiest way to do this would be to sort the array, then return the
first two and last two elements. Using slice() prevents the array itself from being sorted.
Remove duplicate values from array
Basically, we iterate over the array and, for each element, check if the first position of this element in the array is equal to the current position. Obviously, these two positions are different for duplicate elements.
Get all non-unique values
You could sort the array and then run through it and then see if the next (or previous) index is the same as the current. Assuming your sort algorithm is good, this should be less than O(n<sup>2</sup>):
Palindrome check
How to reverse an array
About the Author
Here is my website, portfolio, and works. 👨💻
You can get in touch with me if you have any questions/projects, visit my website/twitter account.
You can follow me on Twitter too.