Skip to main content
6 votes

LeetCode 3542: Minimum Operations to Convert All Elements to Zero

missing docstring def split_non_zeros(self, nums): This is terrible. The identifier is not bad, as far as it goes. But we need to know what the function ...
J_H's user avatar
  • 43.3k
6 votes
Accepted

LeetCode 3542: Minimum Operations to Convert All Elements to Zero

Style First off, let's address a couple of style issues. Looping over indices of a list is better achieved with enumerate than with ...
Chris's user avatar
  • 6,126
6 votes
Accepted

A simple method for compressing white space in text (Java) - Take II

For exhaustiveness, I'd probably suggest your test if loIndex equals hiIndex should test to see if the former is greater than or ...
Chris's user avatar
  • 6,126
6 votes
Accepted

Benchmarking in Java some super linearithmic sorting algorithms

I think the key issue is to make sure you're gathering sufficient information. You're timing one call of each method and using that to compare them. I would suggest you call each method many times1, ...
Chris's user avatar
  • 6,126
5 votes

A simple method for compressing white space in text (Java) - Take II

Readable. (A big plus in my book.) Verbose. I find what benefits I see unconvincing. (Given the ease of copies, the typo // Scan empty suffix is any: is strange.) I'...
greybeard's user avatar
  • 7,819
5 votes

A Java program for compressing/decompressing files via Huffman algorithms (version 1.0.0)

Multiple aspects of this implementation of a Huffman encoder and decoder are inefficient. At the top level, a bit-by-bit tree-walking decoder is inherently slow. Almost every practical decoder uses ...
user555045's user avatar
  • 12.6k
4 votes

Shortest Cell Path In a given grid

Style Let's look at this conditional in shortestCellPathHelper. ...
Chris's user avatar
  • 6,126
4 votes

Jump point search in Java for faster pathfinding in grid mazes

To handle diagonal moves that cross walls, you need to relax the corner-blocking logic in both the jumper and the neighbour finder. Right now, your ...
gdoura mohamed's user avatar
3 votes

LeetCode 3542: Minimum Operations to Convert All Elements to Zero

Simpler Here are some general coding style suggestions. The following: counter = counter + 1 can be simplified using the special assignment operator: ...
toolic's user avatar
  • 16.4k
3 votes

A simple method for compressing white space in text (Java) - Take II

Just some remarks. By providing a capacity: new StringBuilder(textLength) - here a bit extra room, you prevent internal array resizing inside StringBuilder. For ...
Joop Eggen's user avatar
  • 4,716
3 votes

Hackerearth: Counting numbers in an array that are divisible by any 2 numbers

Always assume that coding challenge websites will give you worst case scenarios to test your code. They won't test your code with small arrays of small numbers. They'll give you large arrays with huge ...
Chris's user avatar
  • 6,126
3 votes

Parse path string

Movement conflates at least three different things: tokenising/scanning (part of lexing), evaluating, and application of the path to start coordinates. In other ...
Reinderien's user avatar
  • 71.2k
3 votes

Huffman code builder in Java - computing prefix codes for arbitrary (generic) alphabets - Take II

The HuffmanEncoder is not an encoder. It's a builder that constructs the code table for the symbols based on the weights. An encoder would take input and encode it ...
TorbenPutkonen's user avatar
3 votes

HuffmannEncoder.java - computing prefix codes for arbitrary (generic) alphabets

Minor but, Huffman only has a single n in the name. But let's move on to how the code words are built, the meat of the algorithm after all. ...
user555045's user avatar
  • 12.6k
3 votes

HuffmannEncoder.java - computing prefix codes for arbitrary (generic) alphabets

Style When I look at your formatting in the following snippet, for some reason you have a newline after the first argument to Double.compare, but this line would be ...
Chris's user avatar
  • 6,126
2 votes

Binary Search Tree implementation in C [1]

Style You mix braces and not using braces freely throughout your code. While this works, it leaves open the possibility of adding to branches of conditionals or to loops and forgetting to add braces, ...
Chris's user avatar
  • 6,126
2 votes

Parse path string

Portability I realize this question was posted many years ago when Python version 2.x was prevalent, but now that it is deprecated, consider porting to 3.x. To do so, it is necessary to add ...
toolic's user avatar
  • 16.4k
2 votes

Finding strings in a matrix

I think one of the biggest opportunities here is to make this more generic with the use of templates. We should be able to look for a sequence of values of any type in a vector of vectors. A ...
Chris's user avatar
  • 6,126
2 votes

Inserting into a linked list

If we're assuming that head is not NULL, so let's split up the responsibilities: writing a separate function that finds the tail ...
Chris's user avatar
  • 6,126
2 votes

Benchmarking in Java some super linearithmic sorting algorithms

(I acknowledge title&introduction read benchmarking and comparison. (I suggest to think compare implementations of several algorithms rather than compare several algorithms.) For now going neither ...
greybeard's user avatar
  • 7,819
1 vote

Computing loan cuts leading to a global zero equity in a financial graph (Java)

Comparing to false In more than one place you have code like the following. You should never need to explicitly compare a boolean value to ...
Chris's user avatar
  • 6,126
1 vote

Shortest Cell Path In a given grid

I realize you created this code as quickly as possible for an interview, and your main focus was functionality. Here are some general coding style suggestions. Indentation In the ...
toolic's user avatar
  • 16.4k
1 vote

Hackerearth: Counting numbers in an array that are divisible by any 2 numbers

Portability I realize this question was posted many years ago when Python version 2.x was prevalent, but now that it is deprecated, consider porting to 3.x. To do so, it is necessary to add ...
toolic's user avatar
  • 16.4k

Only top scored, non community-wiki answers of a minimum length are eligible