All Questions
190 questions
2
votes
3
answers
122
views
How to calculate the gradient of an n-dimensional array of data in R
I feel like there must be some function in some package that does this, but for the life of me I cannot find one that calculates the gradient of an array of data points (not a function) by simply ...
2
votes
1
answer
72
views
Efficiently Merging Nested Arrays in PHP While Preserving Unique Key-Value Pairs
I'm working on a PHP project where I need to frequently merge multiple nested arrays. The key point is that I want to preserve unique key-value pairs across the arrays, giving priority to values from ...
3
votes
3
answers
314
views
Optimal way of counting the number of non-overlapping pairs given a list of intervals
I'm trying to count the number of non-overlapping pairs given a list of intervals.
For example:
[(1, 8), (7, 9), (3, 10), (7, 12), (11, 13), (13, 14), (9, 15)]
There are 8 pairs:
((1, 8), (11, 13))
((...
-1
votes
2
answers
70
views
Is there an efficient way to find a subsequence of length 3 where the first is the lowest, the second the largest and the last inside that range?
For instance, given the list [5, 9, 1, 2, 7, 8], the algorithm should find subsequences such as [5, 9, 7] or [5, 9, 8].
I need the algorithm to be efficient. One approach could involve tracking the ...
0
votes
1
answer
74
views
Java Conversion issue - Int to string and again
I am trying to make an integer to string to make slicing operation but the program doesn't gives me any answer it always gives the empty arraylist and While I see the modulus function simply returns ...
5
votes
4
answers
509
views
Calculate max normalized mean subarray in O(n)
This is a variation of max sum subarray problem but there's a little twist (also similar to max average subarray with size k). Instead of finding the maximum sum, I'd like to find the normalized mean, ...
1
vote
2
answers
186
views
Algorithm for border-zeroes and ones in an array
Consider a 2D array that I have named "zeroesAndOnes" that has a random length and width and that has also been randomly filled with zeroes and ones.
I want to know an algorithm that would ...
-2
votes
2
answers
760
views
How to efficiently update items of a huge (100.000 items) array from a smaller (50 items) array?
I have two arrays like this:
let a = [{id: 1, content: 10},{id: 2, content: 20},{id: 3, content: 30}]
let b = [{id: 1, content: 11},{id: 2, content: 21}]
where a is actually huge (~100k objects) and ...
0
votes
0
answers
49
views
Question Regarding the Time Complexity of Algo Finding Common Elements in Unknown Number of Arrays
I am having difficulty understanding the time complexity for my code below regarding the return of common elements in an unknown number of arrays. I was told that my time complexity was O(n^2). ...
0
votes
1
answer
76
views
How can I optimize a query that loops over each day of a month or loops over a given date range?
The following function is called 3 times from a controller with different parameters. Each time 30/31 queries are running according to the dates in a month. In the index page this single function is ...
-2
votes
1
answer
55
views
What are the benefits of using built in functions with cb in js? [closed]
I'm talking about array built-in functions mostly, like reduce, map etc.
The only advantage I see is that you can chain them.
Let's say you need to compute the sum of the elements in array.
const ...
0
votes
1
answer
69
views
Code Challange Joining repeated numbers on an array
my output from a machine learning algorithm is a list of segments, segments are represented by a pair of ids, each segment is part of a track(ideally, there are repeated ids and missing ids), and the ...
2
votes
1
answer
94
views
Java perfomance issue with Arrays.sort [duplicate]
I've been solving one algorithmic problem and found solution, as I thought. But unexpectedly I bumped into a weird problem.
Let's assume i have the following code on java 8/17(replicates on both), ...
0
votes
1
answer
632
views
Algorithm to count unique values in the array using the Multiple-Pointers pattern, used two approaches, which one is better?
The question was to implement a function called countUniqueValues, which accepts a sorted array, and counts the unique values in the array. There can be negative numbers in the array, but it will ...
0
votes
0
answers
34
views
Decrease computation time for finding maximal subarray (Python)
I need to compute an algorithm that finds the maximal subarray of an array of integers (both positive and negative), and then computes the sum of this subarray.
So far I've the following solution, but ...