34
votes
26
votes
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 ...
25
votes
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, ...
23
votes
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 ...
22
votes
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-...
20
votes
Accepted
Pancake sort interview with Python
flip
For starter, you can swap two variables in Python without using a temporary one:
...
20
votes
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 ...
18
votes
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 ...
17
votes
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.
...
17
votes
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 ...
16
votes
Accepted
16
votes
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 ...
16
votes
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 ...
16
votes
Accepted
Converting Roman numerals to integers
Don't use sum as a variable. Especially because you want to use it with your approach!
...
15
votes
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 ...
15
votes
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 ...
14
votes
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 ...
13
votes
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 ...
13
votes
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 ...
13
votes
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 ...
13
votes
Tests for palindromes in C and C++
I've seen a lot of answers here over-generalizing. You're dealing with a std::string, so you can just do:
...
13
votes
Accepted
String Encoder with lower-case output
There are couple of things that might have been done better...
Initilize the dictionary form a static constructor or call the method to initialize the field. The method should not access it internally ...
13
votes
C++ std::optional implementation for tech interview
Here is the list of issues I've found in the implementation in no particular order:
The operator bool should be explicit, otherwise it's allowed to implicitly ...
12
votes
Accepted
Are strings anagram
I think interviewer will not be convinced with this solution because here it is no test of logic.
I'm not sure what you mean by "because here it is no test of logic," but if what you mean is "because ...
12
votes
Accepted
Sort an array of 0s, 1s and 2s in Java
Descriptive names
private static void printSortedArr (int[] arr) {
I don't like these names. I would rather write out array if that's what's being said. E....
12
votes
Accepted
Product of all but one number in a sequence
Here are some things that may help you improve your code.
Use all required #includes
The code uses memcpy, so it should ...
11
votes
Accepted
Remove duplicate characters in a string
Clarify the requirement
You state 'remove duplicate characters' but then your code checks for upper and lower case matches - is the requirement to check for distinct letters, or distinct characters?
...
11
votes
Find char which appears maximal number of times
According to a modern C# and LINQ you could try to "shock" interviewer with solving in a row:
...
11
votes
Area calculator for shapes as an OOP interview test
I see some things that may help you improve your code.
Don't overcomplicate your code
The only thing required of the Shape and ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
interview-questions × 964java × 358
algorithm × 168
python × 150
c# × 142
strings × 102
javascript × 96
c++ × 95
programming-challenge × 93
performance × 75
object-oriented × 55
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