39votes
Deck of cards as an interview exercise
No one but the folks who reviewed your code for the company can say with certainty why you were rejected. It also depends on the position you're applying for. If you're applying for an entry-level ...
36votes
Accepted
PI Calculator, Interview Challenge
In an interview it usually doesn't matter if you actually solve the problem. What is most important is the way you (try to) solve it. If they don't tell you it should be the possibly fastest solution ...
34votes
29votes
Generate a list of 10,000 numbers in random order
In general First and foremost, you were asked to produce a program that generates a list of 10,000 numbers in random orders. You've added far too much complexity. There's no need for input or output (...
28votes
26votes
PI Calculator, Interview Challenge
I'm going to give an alternative approach to tchbot's answer There are places where SOLID prinicpals are required. I don't see this as one of them. Here, we have a simple "Are you capable of ...
26votes
Accepted
Deck of cards as an interview exercise
While not strictly required, we value usage instructions, nicely-modeled data, automated tests, and thoughtful consideration of architectural decisions and simplicity-vs-completeness trade-offs. Given ...
26votes
Accepted
Checking if a number is power of 2 or not
try-with-resources Since Java 7, you should use try-with-resources on your Scanner for safe ...
25votes
Accepted
Check if a string has all unique characters
People are very eager to present their own solutions, so let me attempt an actual review of your code: Your names could be clearer. Strings is not very descriptive, ...
23votes
Accepted
Checking if two strings are anagrams in Python
You can change your if to just be return. You should change your while to an ...
22votes
Tests for palindromes in C and C++
A special case length < 3 seems like a bug. A string aa is a palindrome, and one could successfully argue that a single-...
20votes
PI Calculator, Interview Challenge
Flavio's answer addresses a part of something that matters greatly for this kind of problem: rounding errors will kill you. If you look at the expression: $$1-\frac13+\frac15-\frac17+...$$ This is ...
20votes
Accepted
Palindrome-testing Java program for an interview
It's enough to loop until word.length() / 2, as this will compare the first half with the second half, so no need to go until the end. As you use ...
20votes
Accepted
Pancake sort interview with Python
flip For starter, you can swap two variables in Python without using a temporary one: ...
18votes
Accepted
Roman to Integer
Packaging and style Why does this function accept self as the first parameter? You never use it anywhere, and it doesn't look like this function should be a ...
18votes
Accepted
Conway's Game of Life Object oriented implementation in Java
It's hard to judge a design when there is no information about what you want from it. If you wanted classes and methods, well you succeeded, but that's about it. But if you, for example, wanted ...
17votes
Accepted
Get all combinations of selecting k elements from an n-sized array
Binomial coefficient \$\binom{n}{k}\$ is growing too fast (with \$n\$) to keep a list of all combinations in memory. I would suggest to use yield return instead. ...
17votes
Accepted
Count the occurrence of each unique word in the file
Efficiency I won't say much about efficiency - because without a clear use-case it will be hard to know whether possible changes would be worth the effort - but my main concern would be fact that you ...
16votes
Accepted
Determine if an array is the reverse of a second array
The first comment, is that it would be preferable to factor this into a dedicated method, like areReversed(int[] array1, int[] array2). It would clarify the ...
16votes
Accepted
16votes
Accepted
Tests for palindromes in C and C++
There are some things to be said about your C version as well, but since you explicitly asked about the C++ version (and also because my C-knowledge is not that great), I will leave those for somebody ...
16votes
Leetcode: Valid parentheses
This is a follow up of @Henrik Hansen. Instead, of a switch I would use a Dictionary<T, K>. A Dictionary offers two main advantages: an increase readibility ...
16votes
Accepted
Converting Roman numerals to integers
Don't use sum as a variable. Especially because you want to use it with your approach! ...
15votes
Accepted
LeetCode: LRU cache implementation C#
The indentation is inconsistent: the test class has its {} indented the same as the class declaration, but the main class has them indented one level more. It's ...
15votes
Conway's Game of Life Object oriented implementation in Java
Thanks for sharing your code! OOP doesn't mean to "split up" code into random classes. The ultimate goal of this is to reduce code duplication, improve readability and support reuse as well ...
14votes
Accepted
Equation Evaluator
In real life, I would use knowledge of existing libraries to pull out an almost-finished solution. In particular, I think it is an example for Boost.Spirit, which is what I would use for a real ...
13votes
Checking if a number is power of 2 or not
It incorrectly returns false when the input is 1. \$2^0 = 1\$ Looping up to number is very ...
13votes
xml is XML is xml is XML
Naming There are .NET Naming Guidelines which state that methods should be named using PascalCase casing. You haven't done this for ...
13votes
Elevator design (interview)
As an interviewer, I would consider this to be a failed attempt. Simply put, it's conceptually wrong. No elevator that I have ever encountered acts as a queue. In a single-elevator system, it should ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
interview-questions × 961java × 357
algorithm × 168
python × 149
c# × 142
strings × 102
javascript × 96
c++ × 95
programming-challenge × 93
performance × 75
object-oriented × 54
array × 50
complexity × 49
beginner × 46
linked-list × 44
python-3.x × 38
c × 37
unit-testing × 33
tree × 32
recursion × 24
matrix × 21
stack × 19
multithreading × 18
comparative-review × 18
graph × 18