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

learn more… | top users | synonyms (1)

4
votes
7answers
119 views

Printing a multiplication table

I was recently given a coding test by an employer. After the test, this was the employer's response: "I’d say that a lot of his solutions were pretty inefficient and took a very ‘brute force’ ...
14
votes
5answers
492 views

Given a sequence of positive integers A and an integer T, return true if a continuous sequence of A sums up to exactly T

Here is the source of the question, and my solution is below. Did I determine the worst case correctly? If you find any input where it doesn't work, please let me know. ...
2
votes
1answer
63 views

Highest pit - only climbing through the pit once

For a problem description, see other question. Imagine I would write this code at an interview. What would you say? Time complexity: \$O(n)\$ Space complexity: \$O(n)\$ Auxiliary space complexity: ...
2
votes
1answer
85 views

Find the max. difference between two array elements a[j] and a[i] such that j > i

The source of the problem is here. Given an array of integer elements, return the maximum difference of any pair of numbers such that the larger number of the pair occurs at a higher index ...
3
votes
0answers
48 views

Evaluating an expression with integers, +, and *, as well as -, / - revision 2 [duplicate]

The question came from this web site, and the first round of code review is here. The calculator which only supports the signs + and ...
4
votes
2answers
156 views

Android App Interview (Minesweeper game)

I recently did an Android Minesweeper app for a pre-interview coding challenge before I could talk to any engineer and was rejected. This feedback was given but I'm not sure on some of it. ☺︎ Game ...
4
votes
2answers
265 views

Evaluating an expression with integers, +, and *, as well as -, /

There is a job interview question, and the source of the question is here. The solution is pretty simple. We just need to split the input string by + and then by *. Then we compute products in a ...
5
votes
3answers
100 views

Summing the first 1 to n powers of 2

At a JavaScript test for a job, I was asked the question below. I refuse to believe there isn't a better way to accomplish the same result, but I couldn't find any. If some JavaScript geek would take ...
3
votes
2answers
90 views

Simple Factorial Interview Task

I did this code for an interview. Can you tell me how it looks? I didn't get the job, so I'm wondering what I could do better in my code. ...
1
vote
2answers
63 views

Passing text through a network of transformation modules (task #4)

About a year ago, I was given a C++ assignment as a preliminary job-interview test. The assignment included 4 different tasks, from which I had to choose one. I actually chose and completed 3 out of ...
1
vote
1answer
55 views

Beat count-to-time converter (task #2)

About a year ago, I was given a C++ assignment as a preliminary job-interview test. The assignment included 4 different tasks, from which I had to choose one. I actually chose and completed 3 out of ...
2
votes
1answer
48 views

Rhythm notation converter (task #1)

About a year ago, I was given a C++ assignment as a preliminary job-interview test. The assignment included 4 different tasks, from which I had to choose one. I actually chose and completed 3 out of ...
0
votes
1answer
57 views

Displaying information served on the client

I recently did a coding problem for an interview that unfortunately led me to not getting the position. So I figured I'd get the code reviewed by other professionals because after asking about the ...
17
votes
2answers
617 views

Designing another Coffee Machine Application

After reading Designing a coffee machine yesterday, I decided I could also give the same problem a try. I have used the following problem statement (copied from the given question): Design a ...
27
votes
5answers
3k views

Designing a coffee machine

I was recently rejected from what looked like a really promising string of interviews. I did very well in a questionnaire style review, and then they handed me this assignment (more or less): ...
3
votes
1answer
45 views

Acquiring indices for anagrams of an input string

I am working on an interview question from Amazon Software: Design an algorithm to take a list of strings as well as a single input string, and return the indices of the list which are anagrams of ...
6
votes
2answers
212 views

Finding pairs of numbers within A that add up to N

I am working on an interview question from Amazon Software Interview: Given an integer N and an array of unsorted integers A find all pairs of numbers within A which add up to N I have a working ...
3
votes
1answer
71 views

Letter Combinations of a Phone Number

I was asked to code a solution in Python in 15 mins. Print all possible word combinations for a given phone number. Numbers 0 and 1 will not be part of the phone number, the numbers can be repeated, ...
4
votes
2answers
398 views

Non-recursive method for finding a ^ n

I am working on an interview question from Amazon Software. The particular question I am working on is "to write a program to find an." Here is my recursive solution to this problem (in Java): ...
3
votes
1answer
84 views

Find the smallest number of square numbers to create n

An interview question I got - Given int n, find the smallest number of square numbers that fit inside n. Example: ...
3
votes
2answers
96 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
2answers
100 views

Immutable Queue in Java using an Immutable Stack

I am new to this Immutability concept and I have some coding experience in JAVA. Recently as a part of internship program, they gave me a 5-day task, which was to implement Immutable Queue. After some ...
3
votes
3answers
203 views

Determining if a pair exists in a large sorted array

I'm doing practice interview questions from here. Here is the one I am currently on - if you are given a very large sorted int array, then check of there exists a ...
1
vote
1answer
82 views

Count the accumulated rainfall in a 2D mountain range

Challenge: Count how much rain will be collected in the valleys between the peaks of a mountain range in a 2D world. The mountain range is defined by a single array of positive ...
2
votes
2answers
133 views

Counting a cycle

An interview question I got - Each element of an int array points to the another element, eventually creating a cycle. Starting at ...
8
votes
3answers
200 views

Computing the relative magnitude of the values in one double array to another

An interview question I received: You are given two unsorted lists of positive doubles x contains the results from experiment 1 ...
33
votes
12answers
3k views

Efficiently squaring each element in a sorted array, keeping it sorted

The other day I was asked the following question during an interview: Given a sorted array, how would you square each element of this array, while keeping it sorted? I froze up and wrote a ...
5
votes
2answers
229 views

Find if a word with wildcard exists in dictionary [closed]

This is a question from a phone interview I had. The question was in 2 parts: a. find("cat") -> T/F suggest a data structure to find is if a word exists in a large dictionary, how will one node ...
3
votes
2answers
432 views

Elevator program code challenge

I recently applied for a job where the company gave me the following prompt for a code challenge. They have since told me "yeah, no thanks" but provided me with no feedback about why they came to that ...
2
votes
1answer
148 views

Deep copy linked list with arbitrary nodes

The original question can be found here. I implemented method 2: Please comment about style, unit testing, code complexity, time and memory space and complexity. ...
7
votes
7answers
1k views

Given an array of integers, return all pairs that add up to 100

I was recently given this programming challenge on an interview, and I decided to use javascript to solve it. I did, but I'm not happy with my implementation. I can't help thinking there must be a ...
2
votes
1answer
75 views

3Sum 2 Different implementations complexity

These are 2 implementations for the http://en.wikipedia.org/wiki/3SUM problem, The first one is mine. and in the second one I implemented Wiki's pseudo code. Can someone please tell me if there is a ...
6
votes
2answers
137 views

Tree traversal into List

The interview question was to traverse a tree into a list. ...
5
votes
1answer
101 views

Word break problem with dynamic programming

This is the original question. I have implemented it in both ways. If I enter the word "icecream", should I output "ice" "cream" and also "icecream", or just "ice" and "cream"? Is this a good ...
4
votes
2answers
155 views

Pairing anagrams in a string list

The task was to check for pairs of anagrams in a string list. I first sorted all the words. and looped over the letters. The interview continues with a follow-up, to do the same with limited memory. ...
4
votes
3answers
262 views

String reverse and pairing reversed words

These are questions from an interview: Reverse a string Find matching anagrams in a word list ...
1
vote
2answers
134 views

Implement StringBuilder

I was asked this in an interview yesterday. I could add whatever methods, members and constructors I wanted but I couldn't change the signature of the provided ...
5
votes
4answers
793 views

Finding overlapping time intervals

You have two lists with meetings scheduling (start time, end time). Meetings in single list don't intersect. Find all intersecting meetings across the two lists. Is my complexity \$O(N M)\$? If I ...
1
vote
1answer
2k views

Graph Creation and BFS + DFS in C#

I was asked to implement a graph and BFS and DFS. Please comment. Is it understandable? Is my algorithm correct? Are there any optimizations? ...
1
vote
1answer
116 views

Binary search using recursion, iteration, shifted array

Interview question some engineer, asked me to write binary search in 2 ways, Also asked me to write binary search on a shifted array (10 20 1 2 3 4). Wrote that and then asked me to find the offset ...
5
votes
3answers
182 views

Square root implementations

The question was: Write a function that calculates the root of a given number. Answer A = I wrote it for integers. just run up to half of the number Answer B+C = are for double, using Newton's ...
6
votes
3answers
735 views

One character diff - string comparison

The question was: Create an algorithm to check if two strings differ by one character. This wasn't my interview, so I tried to understand the question. Options: just compare the chars one by ...
1
vote
1answer
142 views

Largest subarray with sum equal to 0

This is a typical interview question: Given an array that contains both positive and negative elements without 0, find the largest subarray whose sum equals 0. I am not sure if this will satisfy ...
6
votes
1answer
210 views

Task scheduler coding exercise

In an interview about multithreading I was asked to write code to satisfy the requirements below: In the exercise you need to provide implementation of single-threaded TaskScheduler class with the ...
5
votes
4answers
199 views

Stack with a minimum

A practice interview question: How would you design a stack which, in addition to push and pop, also has a function getMin which returns the minimum element? Push, pop and min should all operate ...
0
votes
1answer
125 views

Matrix: Set a row/col to zero

A practice interview question: Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0. ...
-1
votes
1answer
125 views

Java interview code [closed]

I was curious to anyone's thoughts, comments, and input as to something I was presented with during a job interview I went to recently. I was provided with some java code and asked to determine what ...
10
votes
4answers
2k views

Counting occurrences of each word in a sentence

I have been doing this test task for C# Developer role at UBS.London recently and have been rejected. No reason stated yet. Was wondering if you can take a look and provide feedback on what I can do ...
12
votes
4answers
1k 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 ...
11
votes
2answers
381 views

Min triangle path - bottom-up

I got a bit intrigued with the recent question DP solution to min triangle path and after a certain chat message I decided that I wanted to implement my solution. Given a triangle, find the ...