This tag is for questions that came up in an interview.

learn more… | top users | synonyms (2)

2
votes
2answers
65 views

JavaScript function to convert decimal number to binary

I was recently asked this in an interview for a front-end position and I came up with something like this which seems to work but is clunky. (Number.toString() was ...
2
votes
2answers
29 views

Choose a color with probability proportionate to its weight in a group of colors

Input: An array of colors with weights. e.g [['red', 10], ['blue', 20], ['green', 30]] Output: A random color from the array, based on it's proportion to the other ...
2
votes
3answers
111 views

Adding minutes to a time value in Ruby

I recently submitted a code-challenge for an interview according to the following guidelines: About Write a function or method that accepts two mandatory arguments and returns a result. ...
4
votes
1answer
41 views

Construct binary tree from inorder and postorder traversal

The problem is taken from here. The tree is guaranteed not to have duplicate elements. My questions is, instead of creating new arrays leftInOrder, ...
4
votes
1answer
37 views

Project Euler - Largest Product In A Grid

My code solves Project Euler problem #011: What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid? I looked over one ...
5
votes
2answers
148 views

Registering and looking up aliases

I've taken a coding challenge as part of a job interview and the recruiting process. Sadly I didn't get through it and couldn't secure the job. I am wondering if anyone can help me out here and show ...
9
votes
2answers
818 views

Stack having push, pop and return min in O(1)

I am using a class which is taking care of minimum value so far. Please let me know of any improvements or suggestions. ...
5
votes
2answers
45 views

Making the same amount from different combinations of coins (top-down approach)

I was reading a typical interview question found here. Given an amount and a list of denominations, count the number of possible ...
1
vote
2answers
137 views

Rotate matrix 90 degrees clockwise

Please suggest improvements and a possible better way of doing it in place. ...
-2
votes
1answer
52 views

Finding Closest Sibling in a BST efficiently

Trying to print the closest sibling in a BST. How can I improve on this algorithm in terms of space/time efficiency? Please point out any potential bugs too! I'd appreciate that. ...
3
votes
1answer
33 views

Sum to zero of all triples in a list - n^2 running time

As part of an interview, I had to submit a code sample to solve the classical "triples sum to 0" problem. The reviewer said the algorithm needed to be in n2 time, and I was later informed that the ...
1
vote
2answers
44 views

Check if the undirected graph is cyclic

Here is my approach. Do DFS and check in stack whether the new node is already in the Stack or not. ...
3
votes
1answer
56 views

Check string having unique character or not without additional data structure

Here is my code without using additional data structures. Assuming all the characters are alphabetical and character checks are case-insensitive. ...
4
votes
2answers
91 views
2
votes
2answers
49 views

Make binary search tree from sorted array

Here is my code for converting a sorted array to a binary search tree. Please review and let me know the improvements or some better way of solving this. ...
0
votes
2answers
58 views

Check if path exists directed graph, without using collection

I have written code to find whether the path exists between source and destination in a directed graph. I have used BFS and instead of ArrayList or queue. I have ...
5
votes
1answer
62 views

Find the largest continuous descending sum in a 2d matrix

Given a 2d array, the problem is to find the largest sum, where each subsequent is >= the previous digit but < all of the 'neighbour' digits. You can only move up, down, left and right. My ...
3
votes
2answers
108 views

Finding if the tree is balanced or not

Can someone please review my code and let me know if there are some bugs or possible improvements? ...
0
votes
1answer
32 views

0-1 Knapsack in Java

I'm looking for advice on coding practices in general. ...
5
votes
3answers
194 views

Print all anagrams together in a sentence in Java

I know a lot of memory is being used, but how do I make this more efficient in space(and time) . ...
5
votes
1answer
68 views

Given a 2D array of digits, try to find the occurrence of a given 2D pattern of digits

My algorithm is quite simple. I simply iterate over the entire map arr and if I find the start of the combination I need to ...
2
votes
1answer
49 views

“Can a list of meetings all be scheduled in a conference room?”

I was given this question at an interview for a position I just got rejected by, so looking to improve and see what better answers there are! ...
6
votes
2answers
88 views

Linked list for interviews

I'm trying to learn linked lists so I can answer interview questions. Even though I've seen plenty of tutorials to understand how they supposedly work, I don't know if I am doing a good job because I ...
4
votes
0answers
75 views

Secret Santa Application : Practical Interview Test

I was given a practical task as part of an interview for a front-end developer position. There is a follow up interview and I'm looking for some constructive criticism / tough love to help me prepare. ...
3
votes
2answers
101 views

Check if sum can be found in array

Given an array a, check to see if z numbers inside a total up to ...
1
vote
2answers
76 views

Check if a linked list is a palindrome in O(n) time and O(1) space

I liked this problem because there are so many sub-problems that are interview problems in their own right-- (reverse linked list, find midpoint) ...
7
votes
1answer
60 views

Counting the overlapping intervals in the union of two sets

I had to recently implement a code to count the union of all intervals (if there are overlapping intervals) for an interview. I was provided with the following function stub: ...
6
votes
2answers
321 views

Reversing a domain name string in Java

Given a dot separated domain name, reverse the domain elements. Example: ...
9
votes
5answers
200 views

Reverse a domain name string

For an interview question, I was asked to do the following: Given a dot separated domain name, reverse the domain elements. Here are a few input/output examples: ...
5
votes
1answer
127 views

Weighted Probability Problem in Swift

I was asked a weighted probability question in a technical interview a few months ago that went something like this: Given an input of colors and an integer "weight" value, randomly return a color ...
8
votes
2answers
302 views

Printing an hourglass pattern

In a recent interview I have been asked to write a program to generate the following output: ...
8
votes
1answer
135 views

Analysing the results of various search engines and determining a winner

This is a programming challenge I submitted as part of a job interview, which I failed because it lacked "maintainability" and "patterns and best industry practices", so I guess we could all learn ...
6
votes
1answer
72 views

Text substitution templating function

In a recent interview I was asked to solve the below problem. Problem: Given a string with variables in them, e.g. ...
3
votes
1answer
103 views

Longest palindromic subsequence by memoization

I've written some code to solve the longest palindromic subsequence problem. ...
3
votes
1answer
138 views

Highest floor of a building from which to drop an egg without breaking it

Problem description: You have two eggs, and need to find the maximum floor of a 100-floor building from which you can drop the eggs without them breaking. Do this with as few attempts as possible. ...
8
votes
4answers
347 views

Implementing common fraction using TDD

Recently, during the interview, I was asked to implement basic arithmetic operations with common fractions using TDD. The task is fairly simple, but I was nervous so I did not do too well. :) Later on ...
10
votes
5answers
1k views

Maximum product of 3 integers in an int array

I want to find the maximum product that can be obtained from any 3 integers in an integer array. The optimal solution has time complexity of \$O(n)\$ and space complexity of \$O(1)\$. I managed to ...
6
votes
1answer
201 views

Finding anagrams

I recently had a potential employer send me a programming test to read through a file and write to another file all the words that were anagrams (two or more words containing the same letter). The ...
4
votes
2answers
98 views

Reverse all the words in a given string

I have read this and I want to know how the solution that I came up with in my interview compares with the top solution. ...
7
votes
4answers
245 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 ...
4
votes
2answers
141 views

App to list books from JSON data

I recently submitted the code for this for an 2 hour interview but I was rejected. The app shows book information with a image, title, and author. Each entry has a title but some entries have no ...
5
votes
2answers
138 views

Project Euler problem 79: deducing a passcode

For one place that I interviewed at (for a Python developer position) I worked with one of the devs on two Project Euler problems, one being problem 79. We talked through different approaches and came ...
2
votes
0answers
56 views

Are AVL trees equal? - revision 3

The original question Given two binary trees, return true if they are structurally identical, and false otherwise. Are AVL trees equal? Are AVL trees equal? - revision 2 This revision on ...
0
votes
1answer
40 views

Taking a node in rootA and finding a clone node in other tree

I was asked this as an interview question. I was also asked to assume that there is a function which can compare and say two nodes are identical. I would like to implement that function as well. I'm ...
2
votes
3answers
93 views

Reverse part of a linked list

I'm learning data structures. I'm working on linked lists at the moment, and I'd like to have a strong grasp on them. Below is the last problem I solved. I'd like to know what you think of the ...
5
votes
2answers
129 views

Bank account data structure

I need to model simple account data structure. The user should be able: to add a transaction get information about transaction take all transaction of some type sum a transaction and all its ...
6
votes
3answers
446 views

Checking balanced parenthesis string

I recently wrote a code in online recruitment test. It was very good. With each question, there were associated space and time limits check. If our code executed correctly within both limits, only ...
1
vote
1answer
60 views

Are AVL trees equal? - revision 2

Revision 1. This revision on GitHub In addition to the solution itself, I wrote tests for all the possible cases. It seems you have verified all execution paths are covered. You are ...
21
votes
3answers
2k views

Java Inventory System

I'm often applying to jobs just to test out my skills. I have recently applied to one, had to submit a Java problem, but got rejected. Could someone please review my application briefly and tell me ...
4
votes
2answers
296 views

Maze solver for 2D matrix in Ruby

I got rejected for a junior Ruby job entry where I had to solve a 2D matrix as a maze with walls. This is the main class: solver.rb ...