[Solved] More efficient way for calculating margin percent given cost price, unit price, and tax information

There are two solutions here – one is the algebra that solves the problem you’re actually presenting (because estimation isn’t required here), and the other is the code for doing the estimating if it WERE required. Algebra: If we express the markup rate and both tax rates as 1 + increase%, it makes our math … Read more

[Solved] Optimal Algorithm [closed]

Just ask any one of them the following question: If you were the opposite to what you are going to be when you answer this question, which would be the right way to go? If he’s the indecisive type in lying mode, he’ll have to tell you to go the wrong way because, as a … Read more

[Solved] What are the techniques of Compression? [closed]

Maybe the simplest lossless one is Run-length encoding the string: WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW will be encoded to: 12W1B12W3B24W1B14W or: WW12BWW12BB3WW24BWW14 And the simplest lossy encoding algorithm would be something like: down-sampling, or averaging over 3 neighbors cells of a vector and keep the average value. 1 solved What are the techniques of Compression? [closed]

[Solved] Hackerrank string reduction

Your problem is that: reduce(“baab”) = ‘b’ + reduce(“aab”) = ‘b’ + reduce(“b”) = ‘b’ + ‘b’ = “bb” You only look at your first character until you can’t immediately remove it anymore. Then you never look at it again, even if at some point afterwards you actually could remove it. I suppose you could … Read more

[Solved] Forming the smallest number [closed]

As others have pointed out sorting and removing duplicates is possible. But how about this algorithm (in pseudocode, implementation is left to the reader)? bool contains(int x, int digit); // returns true if x contains digit in base 10 notation int res = 0; for (int digit = 0; digit <= 9; ++i) { if … Read more

[Solved] Inplace rotation of a matrix

Always use numpy for matrix operations. I’ll assume an m*n numpy array arr. I first did a transpose using the np.transpose function and then I flipped it using the np.fliplr function. output = np.fliplr(np.transpose(arr)) As mentioned in the comments, there is no way to do an in-place replace without a temporary variable for rectangular matrices. … Read more