This tag is for questions that came up in an interview.
-4
votes
0answers
20 views
What should I change in this java project to look like an java expert? [on hold]
I'm really confuse about the interview I did with a firm. They told my code was not expert, but almost intermediate level java.
Basically, the problem was to create a scoreboard to print the game ...
5
votes
3answers
366 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
60 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
99 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
84 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
35 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
127 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
48 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
43 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
151 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
851 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
46 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
154 views
Rotate matrix 90 degrees clockwise
Please suggest improvements and a possible better way of doing it in place.
...
-2
votes
1answer
53 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
53 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
61 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
92 views
2
votes
2answers
57 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
58 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
72 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
114 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
55 views
5
votes
3answers
203 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
78 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
55 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
89 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
89 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
107 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
92 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
73 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
338 views
Reversing a domain name string in Java
Given a dot separated domain name, reverse the domain elements.
Example:
...
9
votes
5answers
216 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
159 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
334 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
139 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
73 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
114 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
349 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
216 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
103 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
247 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
170 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
157 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
1answer
63 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
46 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
97 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 ...