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

learn more… | top users | synonyms (2)

3
votes
2answers
24 views

Detecting if two strings are anagrams using TreeMap

I decided to use Java TreeMap because it seems like a great data structure to fit this problem. However, I am not sure if there could be much simpler methods using ...
2
votes
1answer
27 views

Faster palindrome checker in Java

I wonder if there could be a faster palindrome checker in Java. The best one I have is O(n/2) which is O(n) eventually: ...
3
votes
2answers
19 views

Duplicates in array elements and sorting

I've been given this little test exercise for an interview as php developer, and I'd like to hear from you if my solution is good (enough) or if the problem could have been solved in a better way. ...
2
votes
1answer
41 views

Merge and sorting arrays of String and int in more efficient methods

Are there better methods for merge and sorting arrays of int and String in more efficient methods both time-complexity wise and ...
3
votes
2answers
79 views

C++ Graph Class Implementation (adjacency list)

I've got a barebones C++ graph class implemented as an adjacency list. The graph consists of a vector of vertices. Each vertex has a vector of outgoing edges that store the destination vertex id. ...
5
votes
1answer
90 views

Caches implementation in C++

I had a test task for internship where the main part was in implementing fixed size caches with different displacement policies (LRU/LFU/FIFO). I did that task, but was refused afterwards. Now I am ...
1
vote
0answers
20 views

Checking whether a directed graph contains a cycle

I create a myGraph class as shown below. Then I created an instance of the graph by giving the adjacency list as a NSDictionary and then call the isGraphCycleFree method. Will this answer look good ...
3
votes
1answer
47 views

Efficient File Searching

During an interview I was asked to consider the following: You are trying to find an instance of an error code within a number of log files within a directory. The goal is to count the number of ...
4
votes
2answers
106 views
0
votes
3answers
57 views

Counting occupants in each HouseHold provided large file of comma seperated personnel records

I was given the below Exercise as part of a coding Exercise to do at home for a technical interview, and I did not get through past this round. I would like to get some input on what i could have ...
4
votes
1answer
59 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
45 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
159 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 ...
33
votes
7answers
11k 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
55 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
98 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
49 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
167 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
419 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: ...
2
votes
3answers
79 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
119 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
121 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
37 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
133 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
54 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
50 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
157 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
886 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
56 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
175 views

Rotate matrix 90 degrees clockwise

Please suggest improvements and a possible better way of doing it in place. ...
-2
votes
1answer
57 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
43 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
63 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
3
votes
2answers
62 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
78 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
116 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
70 views

0-1 Knapsack in Java

I'm looking for advice on coding practices in general. ...
5
votes
3answers
230 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
90 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
58 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
94 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
96 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
123 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
111 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
97 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
358 views

Reversing a domain name string in Java

Given a dot separated domain name, reverse the domain elements. Example: ...