This tag is for questions that came up in an interview.
4
votes
0answers
45 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
81 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
51 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
50 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
302 views
Reversing a domain name string in Java
Given a dot separated domain name, reverse the domain elements.
Example:
...
9
votes
5answers
174 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
110 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
252 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
132 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
67 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
76 views
Longest palindromic subsequence by memoization
I've written some code to solve the longest palindromic subsequence problem.
...
3
votes
1answer
134 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
331 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
751 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
186 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
84 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
235 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
105 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
120 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
44 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
37 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
86 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
106 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
416 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
50 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
257 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
...
4
votes
1answer
76 views
Water accumulated between towers
I came across this interview question to find water accumulated between towers:
You are given an input array whose each element represents the height of the tower. The width of every tower is 1. ...
6
votes
2answers
411 views
Implement Java hasNext() and next() in C++
Recently came upon this question asked in interview with major tech company.
Implement Java's next and hasNext function in your favorite
programming language.
Here is the solution I came up ...
6
votes
1answer
212 views
JavaScript program to count lines of Java code
I've implemented a small program in JavaScript to count the number of lines of a string of java source code.
This was done for one of the Code Kata exercise: ...
3
votes
4answers
106 views
Sending templatized e-mail to a million contacts
This code runs fine without a bug, I need to optimize this code for following interview requirement.
Lets say i need to send it to 1 million contacts and emailBody is ~100Kb.
What code optimization ...
2
votes
1answer
66 views
Get K most frequent tokens from a token stream
This is an interview problem:
Given a token stream, find the K most frequent tokens in real time (the order of these k tokens does not matter).
My approach:
Use a hash table (...
4
votes
2answers
143 views
Function to compare phone numbers
I got rejected in tech screen yesterday. I was asked to write a JavaScript function and send it over email. I have also added hiring manager's response at the bottom.
Could you please write a ...
6
votes
3answers
360 views
Finding the postion of a substring in a string
I am given two strings and return the position if in the larger string the smaller string is found. If not I am returning -1 for position. Any suggestions for improving my code.
...
7
votes
1answer
199 views
Are AVL trees equal?
I was inspired by this answer and decided to implement an AVL tree with the methods equals and hashCode as if I was asked to do ...
7
votes
1answer
116 views
Designing yet another coffee machine, Lombok style
After reading Designing a coffee machine, I decided to implement the same problem as an exercise to get to know Guava and Lombok.
I used the problem statement from the given question:
Design ...
-3
votes
1answer
102 views
Implemented Stack using array
I'm going to job interviews soon. How I can improve my coding style and write better code?
...
4
votes
1answer
92 views
Swap items of a linked list in pairs - revision 5
Here is the source of the question.
Given a singly linked list, swap the list items in pairs (reconnect
the pointers, not simply swap the values). For example:
Before: A->B->C->D
...
2
votes
2answers
85 views
Hike in recession by a company based on criteria
I was going through design questions frequently being discussed in interviews and have found a problem which states:
Consider a company which wants to process salary hikes of its
employees ...
5
votes
4answers
617 views
Find the common element in two int arrays
I am preparing for a interview for a junior level c# position. I take two arrays and find the common int between both of them. Let me know if you have any feedback.
...
4
votes
3answers
669 views
Most common occurrence of an int in an array
I am prepping for a junior level interview in C#. I am hoping I can get some feedback on how to improve my code to print the most common occurrence of an int in an ...
1
vote
1answer
64 views
Swap items of a linked list in pairs - revision 4
Here is the source of the question.
The solution on GitHub.
Revision 1.
Revision 2.
Revision 3.
@200_success' suggestions from revision 3:
The iterator's ...
2
votes
1answer
36 views
Swap items of a linked list in pairs - revision 3
Here is the source of the question.
Revision 1.
Revision 2.
When I started the second round of code review, I wanted to make sure that I had included all the possible input types. However, I ...
3
votes
1answer
83 views
Checking for uniqueness within a string
I saw this interview question in the book Cracking the Coding Interview:
Implement an algorithm to determine if a string has all unique characters
The authors solution uses bit-shifting for a ...
10
votes
4answers
948 views
Method to count all comments in single external C# file
I recently had an interview question:
Write a method that counts all comments in a single external file.
It was a timed question and I wanted to know if this is the best way to accomplish the ...
3
votes
1answer
87 views
Swap items of a linked list in pairs - revision 2
The first revision is available here and the code is available on GitHub. I modified the method reversePairs and added mSize to ...
11
votes
1answer
162 views
Concurrency interview
A little while back I had an interview where they posed a problem, in summary:
Watch a certain directory, and process incoming JSON files
These JSON files have various "Type" fields
Every second ...
10
votes
1answer
259 views
House-coloring optimization challenge
I have an interview coming up in the next few weeks, and I'm choosing to be interviewed in Python. I began programming in Python (it was about four years ago), so the syntax is natural to me, but I ...
2
votes
1answer
196 views
Swap items of a linked list in pairs
Here is the source of the question:
GitHub
Given a singly linked list, swap the list items in pairs (reconnect
the pointers, not simply swap the values). For example:
Before: A->B->C->D
...
7
votes
2answers
489 views
Determine if string has all unique characters
I'm working my way through the exercises of the book Cracking the Coding Interview. I'd like to review my solution for the question:
Implement an algorithm to determine of a string has all unique ...