# algorithm

## How can I use Matrix Exponentiation with square operations?

I have an array F[] is defined:

F[i]=1 (if i==1);
F[i]=F[i]*F[i]+F[i] (if i>1);

So some first element of this array are: {1,2,6,42,…}

## Reverse the Number algorithm. I’m stuck

cout<<"enter a number n"<<endl;
int n{0};
cin>>n;
int lastDig{0};
int revNum{0};

while(n>0)
{

lastDig= n%10;
n=n/10;
revNum = revNum*10+lastDig;
}
cout<< revNum <<endl;

This works j…

## Python itertools.product type function with implementation of backtracking

I’m trying to code an function which will have as its arguments a fixed length of lists
and fixed sum of lists. The function will fill the lists only with these numbers: [0, 1, 2] repeatedly. I tried to make it with the itertools.product b…

## Minimum number of iterations

We are given an array with numbers from ranging from 1 to n (no duplicates) where n = size of the array.
We are allowed to do the following operation :
arr[i] = arr[arr[i]-1] , 0 <= i < n
Now, one iteration is considered when we perf…

## How to build a graph from given string of pairs

I have an array of strings that represents the edges of a graph.
For example:
["6 11", "9 5", "11 9", "15 9", "13 15", "12 14", "15 16", "1 16"]

Now I want to…

## How to split range in groups?

I am writing microservice in Dart.
Service run workers by passing command args to workers like: "app.exe -a=1,2,3,4".
So if currentlyActiveWorkers is 4. Then jobs can be splited to sevaral workers like:
first: "app.exe -a=1,…

## What’s the asymptotically lower bound of time complexity that iterate all r combinations of an arraylist length n?

Below is an example of algorithms that iterate all r combinations of an ArrayList of n elements.
It read/write ids array in exactly C(n+1,r) times (I calculate this use wolfram alpha and verified it with some test cases). And it seems that…

## What is the time complexity of using retainAll() function between List and HashMap?

Let’s say i have a nested List which contains n element in it and also i have a HashMap which contains n keys in it. I want to get common elements between the list and hashmap with using retainAll() function. What is the time complexity of…

## JavaScript: confusion about WeakSet and its effects on garbage collection

I have been grinding leetcode and I encountered this question https://leetcode.com/problems/intersection-of-two-linked-lists/ where it asks you to find the intersection of two LinkedList. One solution (not the best one I know) is to use a …

## I am struck at the question in c++, maximum size of L shape formed in a binary matrix?

test cases
[[True, False, True, False, False, False, False, False], [True, True, True, False, False, False, False, False], [True, True, True, False, False, False, False, True], [False, True, True, True, True, True, True, False], [False, Tr…

## R Boruta – merging dataframe with confirmed features by column name

I have run a Boruta algorithm on a large dataset (> 500 covariates), and have got a dataframe of confirmed or rejected features using , which looks like this. Each observation being a feature from my original dataset (pred_recent_pf_bin…

## Algorithm to form two teams from a list of 10 people based on skillindex

I am trying to come up with an algorithm that checks all possible combinations in a list of players and makes two teams of 5 with the closest possible difference in total skillindex. So far I have come up with the following exhausting perm…

## How to run diagnostics on background program?

We have two GoLang microservices(http) & GoLang background program(running infinite loop).
Within micro-service, we have added diagnostic endpoint point(on http), to provide health-check of service. Grafana tool talks to this diagnosto…

## how can i implement dart binary search algorithm?

how can I use this binary search algorithm in the dart main function?
int binarySearch<T>(List<T> sortedList, T value,{int Function(T, T)? compare}) {
compare ??= defaultCompare(); // I can’t understand this line code
var min…

## Is there a faster way of implementing this ‘ranking’ algorithm?

Lets Suppose I have an array of arrays, where each sub array represents a ranking i.e
std::array<std::array<std::string>, 3> rankings = {
{ "A", "C", "B", "D" },
{ "C", &qu…

## How to implement RSI Divergence in Python

I was wondering is there any Python library that covers RSI-Divergence (difference between a fast and a slow RSI) or any guidence about how can I implement its algorithm in Python.

## How to optimally compare if element is in a list of ranges?

I have two 2D lists with one million+ entries. List1 is full of ranges (e.g. [100, 25] meaning the range starts at 100 and has a span of 25, or 100 to 125) and List2 is full of plot points. I have to count how many ranges each point fits i…

## Typescript: variable function arguments depending on the preceding arguments

This question must have been asked before, I’m almost certain of it. Yet:

I can’t find any such question
Typescript has made major leaps in the recent past, thus the existing answers might be outdated.

Something that I commonly use in my…

## Algorithm time complexity program java

How is the following algorithm coded in java (for N = 100) and what is its time complexity?
N is the number of elements of array A and B
A[] is a 1D array made of even numbers
B[] is 1D array made of odd numbers
funct A1(A,B,N):
if N==0
re…

## How to transform it to 1 if statement

How to refactor those 2 if statements into 1. It writes "A" only when both statements are true or when 1st statement is false
If (A==A)
{
If (B==B)
{
Console.Writeline("A");
}

}
else
{
Console.Writeline(&qu…