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

learn more… | top users | synonyms (2)

4
votes
1answer
42 views

Sort a stack in descending order

Maintain current element as the top element in the input stack. Pop all the elements on the ordered stack which are greater than the current element and push them in to the input stack and maintain a ...
2
votes
1answer
42 views

Find the contiguous subarray within an array (containing at least one number) which has the largest sum

Interview Q: Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example: Given the array [-2,1,-3,4,-1,2,1,-5,4], the contiguous subarray ...
5
votes
3answers
133 views

Interview coding test: Searcher

I did a task for an interview and the solution was not accepted. The task was to implement the class search function by name. The number of classes in the input data from 0 to 100000. Class names are ...
24
votes
7answers
10k views

Interview coding test: Fizz Buzz

I was recently given a coding test to complete for a potential client. It was a FizzBuzz-type of thing with a two-hour time limit. I had a request to write basic FizzBuzz, then add a special case, ...
-1
votes
1answer
50 views

Determining whether a string can be rearranged into a palindrome

For a string, count the number of occurences of each character. If at most one character has odd count then the string can be a palindrome else it's not. ...
4
votes
1answer
87 views

Finding number of times each string in an Array of strings occurs in a large stream of characters (i.e large string)

Interview problem: Given a stream of characters (e.g. acacabcatghhellomvnsdb) and a list of words (e.g. ["aca","cat","hello","world"] ) find and display count of each and every word once the ...
1
vote
2answers
43 views

Calculate Kth Row of Pascal's Triangle

Purpose Implement a solution that returns the values in the Nth row of Pascal's Triangle where N >= 0. Math First three rows ...
3
votes
3answers
153 views

Football game using factory and command patterns

I'm really confused about the interview I did with a firm. They told my code was not expert, but almost intermediate level java. Requirements Football Scoring Dashboard Develop an application that ...
6
votes
3answers
412 views

Given an unordered list of numbers, find all pairs that add up to x

I am coding an interview question from Yahoo Software Engineer Intern Interview. Given an unordered list of numbers, find all pairs that add up to x. I have a working solution in Java: ...
0
votes
3answers
67 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, ...
15
votes
2answers
1k views

Python backend interview: task management system for workers

I've recently applied to a backend position and I was asked to complete a take-home interview question. I thought the question was rather simple and I completed in about an hour although I was told it ...
3
votes
2answers
109 views

Decimal number to binary number conversion in JavaScript

I made this decimal to binary conversion as an exercise for myself and because it is obviously often asked during job interviews / tests. Any hints concerning possible improvements welcomed. ...
2
votes
2answers
101 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
36 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
130 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
53 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
47 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
156 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 ...
10
votes
2answers
871 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
51 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
161 views

Rotate matrix 90 degrees clockwise

Please suggest improvements and a possible better way of doing it in place. ...
-2
votes
1answer
56 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
35 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
57 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
62 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
94 views
2
votes
2answers
58 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
60 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
77 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
115 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? ...
2
votes
2answers
68 views

0-1 Knapsack in Java

I'm looking for advice on coding practices in general. ...
5
votes
3answers
221 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
82 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
56 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
93 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
92 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
113 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
99 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
89 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
348 views

Reversing a domain name string in Java

Given a dot separated domain name, reverse the domain elements. Example: ...
9
votes
5answers
228 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
175 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
357 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
141 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
74 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
149 views

Longest palindromic subsequence by memoization

I've written some code to solve the longest palindromic subsequence problem. ...
3
votes
1answer
141 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
355 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
237 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 ...