Skip to main content

All Questions

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
-1 votes
1 answer
343 views

Hackerrank Gridland Metro - using Interval Cover Solution [closed]

Hi there I was hoping to get a better grasp of greddy algorithms while trying to solve this problem: Hackerrank: Gridland Metro and I was trying to apply an algorithm where each grid could be ...
Elliott de Launay's user avatar
1 vote
2 answers
1k views

Calculate transaction balances and find duplicate transactions

In an interview I was asked to solve two JavaScript questions. I thought I did pretty well because I: Covered the edge cases Wrote comprehensive tests Documented the code using jsdoc The interviewer ...
suchcodemuchwow's user avatar
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
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
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
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
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
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
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
1 vote
1 answer
916 views

Hackerrank "Queues: A Tale of Two Stacks" Javascript Solution

Here is the original problem, and below is my solution (passing). It's asking to implement a queue with 2 stacks, which means I cannot simply use Array.shift. I wonder if the solution can be improved. ...
kdenz's user avatar
  • 335
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
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
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
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