New answers tagged

-2

class Solution { HashMap<String, Integer> memo = new HashMap<String, Integer>(); public int solve(int[] coins, int amount, int startFrom) { //0$left, so we can reach 1 way if(amount == 0) return 1; //already -ve amount means this combination wont work if(startFrom < 0 || amount < 0) return 0; /...


0

The only thing that I would perhaps comment on is that it could be done in a way that's shorter and simpler to understand (due to usage of LINQ and a different way of summing up calc (not done using the div by 2 formula)) if not every bit of performance wants to be squeezed out of the solution (I didn't handle chars directly, but worked with strings for ...


3

The Trie approach might be overkill for this question. I think that a plain (ordered) std::set (or std::multiset) would be adequate. The set's lower_bound() member takes you directly to the first entry with the specified substring. From there, we can either count linearly, or use lower_bound again with a new key created by adding 1 to the last character, ...


2

Magic numbers Avoid magic numbers. Magic numbers are just numbers in your code that represent some abstract data value. The problem is that they are spreed within the code. To make changes to these values requires searching the code and often the same values are repeated making the task even more difficult. Defining the magic numbers as named constants makes ...


1

From a short review; In OOP, your objects are supposed to be re-usable I would take the x,y from a parameter I would take the vx, vy from a parameter I would even take the alpha from a parameter Its nicer to call finished -> isFinished, this way the reader expects a boolean to return In update, it makes sense to update the location with velocity, but I ...


6

General observations rustfmt-compliant formatting ๐Ÿ‘ no warnings ๐Ÿ‘ #[derive(Debug)] on everything that might be useful to debug-print ๐Ÿ‘ no tests or main ๐Ÿ‘Ž (I guess this is built in to Exercism?) Some of the remainder of this review might be a little off base because I wasn't able to test the code. Specific observations Use newtypes and/or enums for ...


0

Introduction I have come up with a more efficient solution in terms of the time complexity, although it's still not passing all the test cases. Nevertheless, I decided to post the solution, because it may help someone with a similar problem in the future. Explanation The idea is to divide an initial array into segments of size โˆšn, and for each segment to pre-...


1

Nice solution, find below my suggestions. Creating a list from a set: List<Integer> listaLideresOrdenada = new ArrayList<Integer>(); listaLideresOrdenada.addAll(listaLideres); The set can be passed directly to the constructor of ArrayList: List<Integer> listaLideresOrdenada = new ArrayList<Integer>(listaLideres); Copying the input ...


0

There is no constraint; it's just a limit of each variable (inputs). That was the first thing, now we need to go to each element of this array/vector to check if its digit-length is even or odd by << modular and division operator >>. If it has, we should increment counter; otherwise do nothing (just break). Just do it with each number/element in ...


3

A couple of points. Firstly about the code you have listed. Are the constraints problems to be enforced or assumptions you can make while writing your solution? It's odd to artificially limit it. len does not need to be defined outside the loop. It is overwritten on each loop so could be replaced with let len = inside the loop. Within the for loop, you ...


2

Performance This is a performance only review and does not address any styling or composition. Code examples are focused on performance with no attention given to readability, naming, or re-usability Time complexity != performance Time complexity is not a measure of performance. It is a measure of how performance changes as the input size changes. Two ...


Top 50 recent answers are included