Skip to main content

All 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 ...
ng-hacker-319's user avatar
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? ...
Achref Boukhili's user avatar
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 ...
Thomas Barrett's user avatar
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 ...
CodeYogi's user avatar
  • 5,137
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 ...
Rez88's user avatar
  • 131
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 ...
Ugur Yilmaz's user avatar
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 ...
John Hewson's user avatar
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 ...
Rohit's user avatar
  • 161
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." ...
davidatthepark's user avatar
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: ...
Alish Dhamala's user avatar
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 ...
jmknoll's user avatar
  • 141
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: ...
thadeuszlay's user avatar
  • 3,981
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 ...
Pazuzu's user avatar
  • 183
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 ...
NPN328's user avatar
  • 771
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, ...
Software Engineer's user avatar

15 30 50 per page