Questions tagged [algorithm]
An algorithm is a sequence of well-defined steps that defines an abstract solution to a problem. Use this tag when your issue is related to algorithm design.
algorithm
121,009
questions
2
votes
3
answers
46
views
How do i remove two of the same item from an array [closed]
im working my way through the odin project and looking at for loops and different methods. Im trying to find a way to pass this test :
test('removes multiple of the same value', () => {
expect(...
1
vote
0
answers
39
views
How to prove a problem is unsolvable in a certain Time Complexity?
While discussing the Local Minimum in n x n Matrix Problem with my professor, he suggested that there exists a solution with O(log n) time complexity for this problem. Now, I'm fairly sure he is wrong,...
-2
votes
0
answers
20
views
How to revise Leetcode problems [closed]
How do you guys revise questions like do you solve the question without looking or just go through the code or dry run or something else. For how much time shall I wait to revise a problem again.
If I ...
-1
votes
1
answer
20
views
Why I receive an unknown variable error in my function?
I'm using AlgoBuild and inside the "input_vet()" function there's a while loop and in its condition I recall the variable N, which I assign a value in the main, and shows a unknown variable ...
0
votes
4
answers
48
views
N series of integers, each of different size, get cartesian product
I have something like this:
{'event1': [2000, 3000, 4000], 'event2': [123, 456]}
but with N keys, not only two like the example
I need to get something like this:
[
{'event1': 2000, 'event2': 123},
{'...
2
votes
3
answers
39
views
Find the smallest polygon with a certain edge on a 2d dijkstra graph
Sorry for bad English.
It's somehow called Minimal Cycle Basis of graph algorithm.
I'm currently working on some algorithm to seperate a graph into rooms. Like the example.
I have a graph link like ...
-2
votes
0
answers
56
views
Looking for an opinion on a seemingly bad interview question I was asked [closed]
I was recently interviewed for a software engineer position, and it seems I have gotten a bad interview question from the interviewer. I would like to ask for a feedback about it to make sure I am not ...
1
vote
0
answers
45
views
Find smallest base such that integer exceeds M in O(log M) time
You are given a string s consisting of digits 0-9 and of length at least two. Further, you are given an integer M. Find the smallest base b such that the string s when interpreted in base-b exceeds M.
...
-1
votes
1
answer
73
views
Count the valid segments for input array of numbers
I have an array of numbers of size n, I want to count the segments, (which are subarrays of size 3 or more) based on below condition:
arr[left] = arr[right] = sumOfItems[left+1, right-1],
it means ...
1
vote
1
answer
89
views
Why does the sliding window algorithm not work for this problem statement?
The question is regarding an algorithm which I'm using to solve a problem. The problem statement is: (or view it here)
"Given arrival and departure times of all trains that reach a railway ...
0
votes
0
answers
56
views
Integer solutions for equation with approximated real variable
I'm trying to solve an equation of the kind:
f1(x)*m^2 + f2(x)*m*n + f3(x)*n = 0
for given x real defined up to a certain precision, f1, f2, f3 given linear functions and m and n positive integers, ...
1
vote
1
answer
129
views
Thread pool design
I have a design question about thread pool. Consider the following code:
int main() {
auto po = std::execution::par_unseq;
// If Parallel STL uses TBB as the backend, I think the thread pool
/...
0
votes
2
answers
95
views
Find unique or combination for given array
I have an array of numbers of size n, select all possible distinct increasing subsequence of the array, for each subsequence find the bitwise OR value and return them as result in increasing order.
...
1
vote
1
answer
83
views
Determine which elements of sequence A can be used to create given sequence B in linear time
Let's say we have sequence A and subsequence of A, called B. I need to determine which elements of sequence A could be potentially used to construct subsequence B.
For example, assume A = [1, 3, 2, 1, ...
0
votes
1
answer
37
views
Sorting with AlgoBuild. Why do I get an index is out of range error?
I am using AlgoBuild to make a program that sorts numbers.
This is my attempt:
AlgoBuild translates this chart to the following pseudo code:
PROGRAM main
INPUT int D
FOR i = 0; i < D; i = ...