All Questions
19 questions
18
votes
4
answers
2k
views
O(N) vs O(N * N) for Word Frequency Algorithm
I am trying to come up with a better solution to the following problem:
Statement
You are supposed to write a function which takes the contents of a document in string format and also a whole ...
7
votes
2
answers
8k
views
Find the intersect area of two overlapping rectangles
This is my solution to find the coordinates of 2 overlapped rectangles implemented in JavaScript. Each rectangle is represented by 2 points, each with 2 (x,y) coordinates.
Can this code be improved?
...
7
votes
4
answers
334
views
Add one to a very large integer
I was asked to implement this in an interview a while back. I didn't pass the interview, mostly likely because it took me far too long to do. However, I'm interested to know how well implemented the ...
6
votes
3
answers
879
views
Flatten an array
I have got this interview question which has asked me to write a production level code which flattens the arbitrary nested array of arrays.
Code
...
6
votes
2
answers
305
views
Find top two clothing sizes in the array
I was recently asked this question in an interview. Here is the solution I came up with. Please let know if I could have done this differently or in a more efficient manner.
The question is as ...
6
votes
2
answers
3k
views
Minimum swaps algorithm terminated due to timeout
I have been trying to solve this question.
Given an unordered array consisting of consecutive integers [1, 2, 3, …, n], find the minimum number of two-element swaps to sort the array.
I was able ...
6
votes
2
answers
427
views
Find matching dictionary words given a Scrabble tray
This is a question I was asked in an interview, below is a cleaned-up copy of the answer I gave. Apparently this answer was not satisfactory. How can it be improved?
Question: Given a dictionary of ...
6
votes
1
answer
2k
views
Text justification program
I'm looking for code review comments for text justification problem described here.
Problem:
Given an array of words and a length L, format the text such that each line has exactly L characters and ...
5
votes
3
answers
2k
views
LeetCode 189 - Rotate Array
I have a working solution for this problem that was accepted in LeetCode:
Given an array, rotate the array to the right by k steps, where k is non-negative."
...
5
votes
3
answers
126
views
Array's reverse vs simple arithmethic
I was asked to print numbers from 100 to 1 in a for loop with the index starting from 1. I came up with this solution:
...
4
votes
3
answers
2k
views
Removing duplicates from an array
I recently wrote this JavaScript algorithm for removing duplicates from an array as part of a job interview process, but was turned down for the position after submitting the code. I didn't receive ...
3
votes
1
answer
580
views
Find the largest product of an array
This task is taken from www.interviewbit.com
Given an array of integers, return the highest product possible by
multiplying 3 numbers from the array
Input:
...
2
votes
1
answer
4k
views
Left rotation arrays algorithm
This is my solution to the common 'Array Rotation' algorithm. As I am currently practicing for coding interviews, I want to make sure that my code in fact valid for coding interview scenarios. Would I ...
2
votes
3
answers
1k
views
Find the 'n' most frequent words in a text, aka word frequency
I'm doing freeCodeCamp's Coding Interview Prep to improve my JavaScript skills. This challenge is called "Word Frequency", and is based on the Rosetta Code's entry of the same name.
The ...
2
votes
3
answers
469
views
Minimum element in a sorted rotated array
A sorted array [0,1,2,3,4,5] when rotated n times (3 times in this case) becomes [3,4,5,0,1,2], meaning elements in the front move to the end. The code below finds the minimum element in this array, ...