This tag is for questions that came up in an interview.
5
votes
2answers
52 views
Find if a word with wildcard exists in dictionary
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
92 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 ...
0
votes
0answers
35 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
6answers
764 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
41 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
95 views
5
votes
1answer
52 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
80 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
120 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
58 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
314 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
121 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
52 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
147 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
315 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
80 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
71 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
141 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
50 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
88 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
879 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
943 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 ...
9
votes
2answers
144 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 ...
6
votes
5answers
180 views
DP solution to min triangle path
I am studying for interviews for various companies. I wrote a solution to this problem, but if an experience programmer looks at it I am sure there are certain areas the code can be made in to a more ...
6
votes
5answers
688 views
Given a String, return a boolean if it is a number
Yesterday in an online interview, the interviewer asked me this question:
If I give you a string, you have to return if a string is number or
not. You are not allowed to use any parse function ...
3
votes
3answers
367 views
pyramid numbers in alternative reverse order
I was asked to write code for the below structure:
1
3 2
4 5 6
10 9 8 7
11 12 13 14 15
And I tried the below code, which works, yet I'm wondering ...
3
votes
1answer
139 views
Finding the longest unique sub-string in a string
I recently interviewed with a company for software engineering position. I was asked the question of finding the longest unique sub-string in a string.
My algorithms was as follows:
Start from the ...
8
votes
3answers
462 views
Basic string compression counting repeated characters
My task was to implement a method which performs basic string compression by counting sequences of repeating characters. Given "aaabbbccc" it should return ...
2
votes
1answer
121 views
How should I write function to print a singly linked list in a reverse order?
I am preparing for interview and I want to write the function in the way that the interviewers will expect me to write. This is my solution:
...
5
votes
2answers
789 views
Remove Nth Node from End of Linked List
I am solving the well known problem Remove Nth Node From End of List:
Given a linked list, remove the n-th node from the end of list and
return its head. Assume that n is between 0 and the ...
2
votes
1answer
126 views
Encoding and decoding exercise
I was issued the following coding challenge from a company to write an encoding and decoding function:
Encoding: This function needs to accept a signed integer in the 14-bit
range [-8192..+8191] ...
7
votes
2answers
150 views
Espresso Queue simulation
I was asked to do a technical test with the following specification, but my solution was rejected and I was not selected for the available position (Junior to "normal" level, with 4 days of time to ...
1
vote
2answers
54 views
Number of maximal PAIRS-values
I had an interview question like this:
In a company there are different people. One can measure how well they
suits for pair coding as follows:
First, let us compute the PAIRS-value which ...
3
votes
1answer
148 views
Interview task to efficiently find compact representation of nodes in tree and find big O time
I recently had an interview problem where I was asked to find a compact representation of nodes in a tree.
As an example, consider the following tree:
...
1
vote
1answer
442 views
Print all permutations of a given string in Java
I want to print all permutations of a given string in Java. To do this I create one auxiliary array boolean used[] to check if I have used some character or not.
...
5
votes
1answer
1k views
Print all possible combinations of size r, from an array of size n
This is my working solution for the following problem: given an array of integers of size n, print all possible combinations of size r.
Before I proceed to the solution, I have the following ...
11
votes
3answers
298 views
Recursive, nested list traversal
Given a nested list of strings (which may contain other nested lists), print the contents of the list and the corresponding depth.
Here is my solution:
...
30
votes
9answers
3k views
Which FizzBuzz is better, and why?
I was in an interview and the guy asked me to do the typical FizzBuzz question of printing numbers 1-100, but for each factor of 3 print Fizz, each factor of 5 print Buzz, and each factor of both ...
1
vote
3answers
351 views
Alternating split of a given singly linked list
Write a function AlternatingSplit() that takes one list and divides up its nodes to make two smaller
lists 'a' and 'b'. The sublists should be made from alternating elements in the original list. ...
8
votes
2answers
627 views
Bowling game scorer
I was given a simple coding exercise as part of a job interview process, for which I received a negative review.
This is the question:
DiUS is starting a bowling club. To help with the club, we ...
10
votes
2answers
151 views
Finding the next number in sequence
I have a question to find the N th number in the sequence.
1
11
21
1211
111221
312211
13112221
1113213211
The next ...
8
votes
2answers
610 views
Animal choir simulator
I got a PHP developer interview test to solve for a company. I didn't get the job but I would like to know where I was wrong. Did I understand the test completely?
...
10
votes
1answer
295 views
Find the peak stock price for each company from CSV data
During the hiring process, a company gave me this test:
Q) Consider Share prices for a N number of companies given for each month since year 1990 in a CSV file. Format of the file is as below ...
7
votes
3answers
333 views
Find two unique integers in sorted array
I have to write the following method:
I have sorted array of integers and in this array every integer repeats twice, except two elements. I have to find these two elements.
Input: 1, 1, 2, 3, 3, ...
10
votes
3answers
2k views
List all possible numbers from a given array that sums up to a given number
I have to solve the following problem: Given an array of integers and given an integer value, list all possible numbers frm the array that sums up to the given value.
Example:
Input: array = {1, 2, ...
6
votes
2answers
2k views
Binary Search Tree implementation using templates
I wrote this implementation using templates. It works fine and as expected. Just want to know if this can be improved. I have some specific questions too at the end. Please feel free to critique to ...
27
votes
10answers
3k views
What are some indicators that I was over-thinking my solution to this problem?
This question is a cross between career question and a code review. I was uncertain where to ask, but since there is code involved I went with CodeReview.
I’m going through the process of technical ...
8
votes
2answers
1k views
Implementing division without addition, multiplication, division or subtraction - follow-up
This is a follow-up to this question:
Division without using addition, multiplication or division
Could you please tell me if there is better way of performing division without ...
0
votes
1answer
165 views
Division without using addition, multiplication or division [closed]
Could you please tell me if there is better way of performing division without +, * or /?
...
6
votes
1answer
140 views
Russian doll envelops
Interview question from the interwebz
You have a set of envelopes of different widths and heights. One
envelope can fit into another if and only if both the width and height
of one envelope ...