Questions tagged [interview-questions]
This tag is for questions that came up in an interview.
102
questions
40
votes
4
answers
7k
views
Rainfall challenge
About a year ago when I was applying to jobs for the first time, I had an interview at a company and they posed the following problem to me, which I preceded to bomb.
A year later I actually came up ...
7
votes
1
answer
2k
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
...
42
votes
5
answers
36k
views
Designing a coffee machine
I was recently rejected from what looked like a really promising string of interviews. I did very well in a questionnaire style review, and then they handed me this assignment (more or less):
...
22
votes
4
answers
6k
views
Determining if an answer can be generated
How can I improve my code below for the following question? While it works, I am not satisfied with how it looks; I was hoping I can somehow keep it recursive, and have the ans filled up inside the ...
6
votes
5
answers
7k
views
Validate that brackets are balanced
I've done a test for a job (which I failed) and I'd like to know in which ways my code could've been better.
Here are the questions and my answers, it's not very long.
1) Make a program that ...
21
votes
4
answers
2k
views
Finding the sub-array with the maximum sum - my approach
This is the code I ended up with that implements the approach I described in a recent answer to another question about the same problem
The basic idea here is to not loop through more things than ...
3
votes
1
answer
150
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 ...
2
votes
1
answer
75
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 ...
216
votes
4
answers
23k
views
Calculate SHA1 hash from binary and verify with a provided hash
I applied for a job and they asked me to write code with the following requirements:
Get a "toolbar offer" description from
http..update.utorrent.com/installoffer.php?offer=conduit. Parse the
...
59
votes
11
answers
13k
views
Sales tax calculator, rejected for being not OOP
I applied for an Application Developer position. They require all their applicants to complete 1 of 3 programming assignments. I picked one for sales tax calculation. It was quite simple.
Write ...
39
votes
10
answers
9k
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 ...
10
votes
2
answers
2k
views
Missing level of technical depth (Common Ancestor)
I recently have given a coding test in a reputable IT company. There were three coding questions.
They refused me by saying that
as we felt they didn't demonstrate the level of technical depth we'...
20
votes
3
answers
4k
views
Reversing k-sized sequences in a linked-list
Here is my solution to this problem; please be brutally honest/strict, if I would have written this code, in a 45 minute interview, what would you think? (I am aiming for Google,Facebook).
Here is ...
6
votes
3
answers
2k
views
Missing level of technical depth (Flatten Tree)
I recently have given a coding test in a reputable IT company. There were three coding questions.
They refused me by saying that
as we felt they didn't demonstrate the level of technical depth we'...
6
votes
1
answer
1k
views
Missing level of technical depth (Recursive to Iterative)
I recently have given a coding test in a reputable IT company. There were three coding questions.
They refused me by saying that
as we felt they didn't demonstrate the level of technical depth we'...
5
votes
4
answers
290
views
Product of all but one number in a sequence - Follow Up
This question is a follow up question to the Product of all but one number in a sequence.
I am posting a new code here with taking into consideration the suggestions of [Edward], [CiaPan], [chux], [...
8
votes
1
answer
716
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 ...
6
votes
5
answers
805
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 ...
4
votes
1
answer
548
views
Improving time complexity of finding the longest palindrome in Python
The Longest Palindromic Substring challenge from InterviewBit:
Given a string S, find the longest palindromic substring in S.
where a "substring" must be contiguous, and in case of ties ...
2
votes
3
answers
3k
views
Find all triplets in array that add up to a given sum
Given an array and a value, find all the triplets in the array whose sum is equal to the given value. For example, if the given array is {12, 3, 4, 1, 6, 9} and the ...
1
vote
1
answer
90
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 ...
96
votes
16
answers
9k
views
Outputting the names of cars, without repetitions, with the number of occurrences in order of decreasing repetitions
A short while ago, I have submitted a coding exercise to a
potential employer. The response came back the next
morning and you can guess what it was from the subject
of this post.
I am not ...
151
votes
20
answers
31k
views
Searching an element in a sorted array
I was applying for a position, and they asked me to complete a coding problem for them. I did so and submitted it, but I later found out I was rejected from the position. Anyways, I have an eclectic ...
30
votes
8
answers
49k
views
Find all the missing number(s)
Recently I've attended an interview, where I faced the below question:
Question: "There is an sorted array. You need to find all the missing numbers. Write the complete code, without using any ...
25
votes
7
answers
5k
views
Sales Tax Problem, rejected for not being up to their standards
I applied for a Junior .NET Developer Position recently, and I was asked to solve a problem (Sales Tax Program) and I was rejected for some reason. The question goes like this:
Basic sales tax is ...
32
votes
3
answers
42k
views
Overlapping rectangles
I received the following question in a technical interview today (for a devops/SRE position):
Write a function which returns true if the two rectangles passed to it
as arguments would overlap if ...
16
votes
4
answers
78k
views
FizzBuzz implementation
The common FizzBuzz implementation I saw is using a check for % 15 for printing "FizzBuzz"
Would you let me know if there is anything wrong / better with this approach?
...
12
votes
10
answers
7k
views
Tests for palindromes in C and C++
A question I've been asked on interactive phone screens is to code a test to determine whether a string is
a palindrome or not. I am providing two examples here: one in C and one in C++. They both ...
8
votes
3
answers
2k
views
Reorder a list of courses, given their prerequisites
I recently graduated from college and applied for a position with a company. I was sent a coding exercise as part of the process. After completing the exercise and submitting it I was told that the ...
20
votes
2
answers
5k
views
Designing another Coffee Machine Application
After reading Designing a coffee machine yesterday, I decided I could also give the same problem a try.
I have used the following problem statement (copied from the given question):
Design a ...
17
votes
5
answers
25k
views
Longest palindrome in a string
Please be brutal, and judge my code as if it was written at a top 3 tech company, straight out of college. (The method signature, and input parameter is given by the problem, so don't worry about that)...
13
votes
3
answers
881
views
Reversing a linked list
I implemented reversing a linked list in iterative way, just by knowing we need 3 pointers and I have never seen a code before, when I coded. I ran this code and tested it, it works fine. Even for ...
13
votes
3
answers
18k
views
Counting permutations without repetitions for a number or a string
Can I make the following code faster with minor modifications? It times out on CodeWars website.
...
10
votes
2
answers
14k
views
Add one to a number represented as an array of digits
I submitted this problem for an interview, and I was wondering if I could have done better. My solution works, and I solved in about 12-15 minutes. I feel like I did a bad job with the code. Please ...
14
votes
1
answer
10k
views
Printing a Binary Tree top-down (column wise)
We have a binary tree, suppose like this:
8
/ \
6 10
/ \ / \
4 7 9 12
/ \
3 5
We have to print this binary tree in top-down ...
11
votes
2
answers
4k
views
Fizz Buzz interview question code
Reading Jeff Atwood's "Why Can't Programmers.. Program?" led me to think that almost all of the solutions would not be something I would want in my own code-base. The Fizz Buzz program specification ...
8
votes
3
answers
3k
views
Elevator Interview Problem OOP - Revised
Elevator program code challenge, revised:
Can someone please critique my Elevator problem - I wanted to use OOP principles and coding standards. Also, does logic make sense?
...
8
votes
4
answers
16k
views
Find the subarray with the max sum
In an interview I was asked to solve the following problem:
find a subarray with max sum
I have written a piece of code for the same. I need your help in reviewing this code.
...
6
votes
2
answers
858
views
XOR linked list implementation
I am trying to resolve below question in order to prepare for an interview xD
An XOR linked list is a more memory efficient doubly linked list.
Instead of each node holding next and prev fields, it ...
5
votes
4
answers
4k
views
Expense-sharing calculation
Friends A, B, C, D go for a trip.
They spend on various expenses.
Cost of the expense is shared.
Example :
A spends 100 for breakfast for A, B, C and D
D spends 500 for cab for B and C
B spends 300 ...
24
votes
3
answers
8k
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 ...
13
votes
1
answer
1k
views
Interview coding challenge for iOS Part 2 - the application in Objective-C and Swift
I recently interviewed with a company that needed a C/C++ programmer to work on the iOS side of the products. The job description indicated they needed someone with 4 years of Objective-C and iOS ...
12
votes
1
answer
943
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 with ...
12
votes
7
answers
30k
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 ...
11
votes
4
answers
808
views
Product of all but one number in a sequence
I was given the following prompt in a coding interview:
Given an array of integers, return a new array such that each element at index i of the new array is the product of all the numbers in the ...
10
votes
2
answers
261
views
Python implementation of find_all_indexes
I got asked this question before in an interview.
For example, find_all_indexes('ababc', 'abc') returns 2. This Python function ...
9
votes
5
answers
1k
views
Find first non-repetitive char in a string
I just had an interview for the C#.NET developer position and I was asked to find the first non repetitive char in a given string without using any library functions but just the basic constructs of ...
8
votes
3
answers
8k
views
Approximate String Matching Interview Question
I was working on the challenge Save Humanity from Interviewstreet for a while then gave up, solved a few other challenges, and have come back to it again.
The code below generates the correct ...
7
votes
2
answers
1k
views
Reversing a domain name string in Java
Given a dot separated domain name, reverse the domain elements.
Example:
...
5
votes
2
answers
2k
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 ...