New answers tagged

6 votes

Leetcode : First Missing Positive

You search for a "1" first, starting at index 0, exchange it with the element at index 0, if found, and then search for "2", starting at index 1, a.s.o. That is something similar ...
Ingix's user avatar
  • 161
6 votes

Leetcode : First Missing Positive

The only clue the code presented offers as to what it is all about is the name of the sole public instance method. Do not follow bad examples, e.g. set by challenge sites. Commendable habits: name ...
greybeard's user avatar
  • 6,346
3 votes

Simple authentication server

My considerations: You hash passwords (but a hacker could use a rainbow-table), so store only salted and hashed passwords having a (wild guess) 64-char-salt and a modern hash algorithm please. You ...
Grim's user avatar
  • 582
1 vote
Accepted

First order hidden Markov model with Viterbi algorithm in Java

In your repository, you need to de-indent all of HiddenMarkovModel.java. sumPathProbabilities can be written in stream form as <...
Reinderien's user avatar
  • 60.8k
3 votes

Parsing Java's class file

Your reference is extremely out-of-date; refer to version 21. Luckily the JVM hasn't changed much. Typer seems like overkill for a program that unconditionally accepts one command-line argument. I ...
Reinderien's user avatar
  • 60.8k
1 vote

Find the greatest possible non repeating sub-string in a string in java

The algorithm that you are trying to implement is not described anywhere. Your code is lacking from a style view: proper indentation; proper amount of newlines; not using spaces where they enhance ...
Maarten Bodewes's user avatar
2 votes
Accepted

2048 game in Java

UX it would be more convenient if both lower and upper case letters were accepted. This can be achieved easily using Character.toUpperCase(...) method when ...
morgwai's user avatar
  • 389
0 votes

2048 game in Java

Generally speaking, the code layout looks good and you used meaningful names for variables, functions and classes. That being said, it would be better to reduce the length of the 2 longest lines of ...
toolic's user avatar
  • 1,406
2 votes
Accepted

Semi-dynamic range minimum query (RMQ) tree in Java

Context RMQ is not as a well known problem as say sorting, so I personally had to search the web first to even know what this is exactly about. I had a quick look at the Wikipedia article, where one ...
morgwai's user avatar
  • 389
1 vote

Calculator Object Oriented Design

What about designing it in such a way that more operations can be added later and different calculation logic can be implemented by extending the base class. ...
Anant Bhargatiya's user avatar
1 vote

Maximum Sum BST in a Binary Tree

Beyond method naming and a comment stating what the signature boolean isBST(TreeNode root,…) suggest, the code gives no indication what it is there for, what the ...
greybeard's user avatar
  • 6,346
1 vote

Maximum Sum BST in a Binary Tree

Is there anything I can change, in the same given code, that would optimize it and/or get it accepted? Your “Time Limit Exceeded” question is basically asking “when is this code slow?” We tend to ...
J_H's user avatar
  • 22.2k
3 votes

Java code to delete all empty folders within a directory

You're using an actual logger - that's good. However, for the errors that appear in cleanupDirectory, it's probably a better idea to throw an exception. The caller ...
Reinderien's user avatar
  • 60.8k
3 votes

Java code to delete all empty folders within a directory

You're not taking into account loops created by symbolic links. This may not be a problem to your use case but in a generic case it will lead to a stack overflow error. A quick but a bit dirty fix ...
TorbenPutkonen's user avatar
2 votes

Java Clean Code, use of enums in data structure

It is important to understand one thing about Clean Code. Clean Code gives people a convenient and easy to remember abstraction when they want to talk about good programming practises. But when you ...
TorbenPutkonen's user avatar
5 votes

Lazily decode a buffer with a thread-safe Iterator

In its current form, the code doesn't work: unless it's an inner class of some enclosing one, the constructor should not be private; Utils.getInt(...) needs a ...
morgwai's user avatar
  • 389
3 votes

Pascal's triangle in Java

Avoid importing * - it pollutes your namespace. The structure of the program is not very Java-idiomatic. The typical Java pattern would be to instantiate an object ...
Reinderien's user avatar
  • 60.8k
3 votes

Pascal's triangle in Java

cite your reference (took me 2 & 1/2 hrs to find the logic) Please don't make your reviewers and maintenance engineers go hunting for the reference you eventually found. Include the URL in the ...
J_H's user avatar
  • 22.2k
1 vote

Java Clean Code, use of enums in data structure

Have you concidered to use boolean (not Boolean but boolean)? Example: private boolean stateClosed; // or window1stateClosed if you like A few advantages: You ...
Grim's user avatar
  • 582
3 votes

UriValidator (+ tests)

This class definition starts off well by describing which RFC is being adhered to and what it is trying to do. It is not entirely clear why the slash separator characters would be included as part of ...
Maarten Bodewes's user avatar
2 votes

Java Queue data structure

It seems that your class is not in fact a queue. It seems to be a domain class for some kind of an airport management system. You should describe in your questions what your code does, not just what ...
TorbenPutkonen's user avatar
4 votes
Accepted

Java Clean Code, use of enums in data structure

Let me start off by addressing this point. As you can see, I have used enums in an attempt to make the code easier to understand and maintain. But my question is, for the windows state and turn, is ...
davidalayachew's user avatar
1 vote

Bit vector in Java supporting O(1) rank() and O(log n) select() - follow-up

The bit-reversals that are part of building a selectorIndex shouldn't be necessary. Perhaps without them, you may need the lookup table to have a different order, I ...
harold's user avatar
  • 9,474
1 vote
Accepted

Java Queue data structure

Advice 1 - Put the class in a package It is customary in industrial code to put each class in a specific package. Perhaps you could start with this: ...
coderodde's user avatar
  • 27.6k

Top 50 recent answers are included