8

The algorithm is good, but... Use a better function name than getMinimumCoins. The task isn't about coins. Python prefers snake_case and four-space indentation. If the list is empty, you crash instead of returning zero. No need to actually perform the increments in the array, and itertools.accumulate can help: from itertools import accumulate def ...


7

As already mentioned by Peilonrayz, your algorithm's time complexity is \$\mathcal{O}(n\log{n})\$, because of sort(). You also process the input array three times: once to sort, once to increment elements as necessary to ensure there are duplicates, and once to calculate how much you incremented. To get the best performance, you want to have a sorting ...


4

Sources of slowness The actual calculations you are doing are fine, I don't see anything you can optimize that the compiler won't already do for you itself. The main overhead will be caused by R repeatedly having to call integral_CppFunctionCUBATURE(). The first issue I see is that you are passing NumericVector Zt_pos by value, but all the doubles by ...


3

There are some readability concerns to me: startTime, endTime, profit are all arrays. The names should be plural to make this obvious. possibleStarts consists of both start and end. It's confusing. You could instead make an array of job objects with properties start, end, profit. Then you wouldn't need the extra profit lookup either. helper is not a good ...


3

You need to be observant of the bounds in the problem description, in particular they allow k=n which means your worst case time complexity is not constant k times O(n), it's actually O(kn), and when k is approximately n, then it turns into O(n^2). I solved a similar problem a while ago and did some interesting benchmarking. I'm not sure why you don't want ...


3

Performance How can I improve the performance of my transforms? So far, only some small ideas. float vs. double math Do not call run-time double functions and constants for float math. A lot of time can be spent up and down converting. // const float s1 = cos(1.0/16.0 * M_PI)/2.0; define M_PIf 3.14159265f const float s1 = cosf(1.0f/16.0f * M_PIf)/2.0f; ...


3

I don't think that your Scoring class is a great place to store constants. (Even if it was, a regular class with statics would be a better fit than a singleton dataclass.) If you wanted to do something like this, make a module instead of a class to get a cheap namespace. Given how these figures are used I'm going to propose that they just be moved inline. It'...


2

Influx should not be capitalized as it's a variable name None of this code: with open("config.yaml", "r") as ymlfile: cfg = yaml.load(ymlfile,Loader=SafeLoader) server_URL=cfg["InfluxDB"]["server_URL"] token=cfg["InfluxDB"]["token"] org=cfg["InfluxDB"]["org"] Influx = ...


2

It is possible to achieve a much better performance in a brutal way result with the use of auxiliary sorted k size array obtained copying and ordering the first k elements from your nums array: int length = nums.length; int lastIndex = k - 1; int[] arr = Arrays.copyOf(nums, k); Arrays.sort(arr); Once you initialized the arr array for every remaining ...


1

I'm gonna guess that the code is really trying to find the diff between two tree structures. Futher, I'm assuming from the name "typeObjCopy" that the two trees have identical structure, just different labels. I.e. no added categories allowed. Hopefully this will still be helpful for you even if I'm not entirely correct about this. When I saw the &...


1

Awesome work. Some further suggestions are mentioned as below. Consider to add some unit tests with a testing framework What I'm most interested in is the correctness of the template-metaprogramming You can add some tests for verify the correctness. No matter the single layer cases or multiple layer cases, and the usage of various types of activation ...


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