Algorithm to generate possible combinations of players from all players of team
Let's say I have 3 postions [goalkeeper, midfilder, striker]
and 6 players
[{"name":A, "position":goalkeeper, "salary":300, "rating" : 9},
{"name": B, "position":goalkeeper, "salary":200, "rating" : 8 },
{"name": C, "position":midfilder, "salary":400 , "rating" : 9},
{"name": D, "position":midfilder, "salary":300 , "rating" : 7},
{"name": E, "position":striker, "salary":400, "rating" : 9 },
{"name": F, "position":striker, "salary":200 ,"rating" : 7}]
Now I need to build all possible combinations of teams with all 3 positions from 6 player with maximum ratings and within my total budget salary of 1100.
Output should be like this
[{ "team" : [A,C,E],
"total_salary" : 1100,
"total_rating" : 27
},
{ "team" : [B,C,E],
"total_salary" : 1000,
"total_rating" : 26
},
{ "team" : [A,D,E],
"total_salary" : 1000,
"total_rating" : 25
}.. all possible combinations. Players will be choosed based on position. there can't be 2 players with same position.]
I found bit of solution here : combinations of players for a team in C But it seems in C but seems not feasible and I need it in JAVASCRIPT.
See also questions close to this topic

Uncaught (in promise) ReferenceError: modifyVideoDoneWindow is not defined  ServiceWorker
I am trying to implement Google Push Notifications, but I am having a problem with with serviceworker. Everything works fine, but suddenly I started receiving this error message in the console. When I call the function modifyVideoDoneWindow(payload) from my onMessage function( When the user in the page), there is no problem. I think the problem is about scope..
Error: "Uncaught (in promise) ReferenceError: modifyVideoDoneWindow is not defined"
// Initialize the Firebase app in the service worker by passing the config. firebase.initializeApp(config); self.addEventListener('notificationclick', (event) => { event.waitUntil(self.clients.openWindow('http://localhost:8080/#videodone')); event.notification.close(); }); // Retrieve an instance of Firebase Messaging so that it can handle background messages. const messaging = firebase.messaging(); // Handle Messages, when the page is closed. messaging.setBackgroundMessageHandler( (payload) => { console.log('Received background message in the service worker PAYLOAD', payload); console.log("Notification status: ", payload.data.status); // Customize notification here var notificationTitle = 'Video Making Tool'; var notificationOptions = { body: 'Your video is ready.', icon: '/logo......' }; modifyVideoDoneWindow(payload); return self.registration.showNotification(notificationTitle, notificationOptions);
});

Trying to compare arrays to determine if values are the "same"
this is my first time asking a question here so my apologies if it's a bit novice. I'm getting jammed on this quick little problem I'm trying to solve and was wondering if anyone had any suggestions on how i could improve this. Essentially, I'm given 2 arrays to start, the objective is to determine if the contents of array1 are equivalent the square root of the contents of array2.
If all values in array1 are the square root of all contents in array2, the algorithm should simply return 'true'. If not, return false. Fairly simple, but my current code is passing all but 1 test. Any pointers on how I could approach this better are greatly appreciated! I think my primary issue here might be the order of how I set up my conditional statements.
function comp(array1, array2) { if (array1 === null  array2 === null) { return false; } if (array1 === undefined  array2 === undefined) { return false; } var squares = array2.map(element => Math.sqrt(element)); for (var i = 0; i < array1.length; i++) { if (array1[i]!== squares[i]) return false; } return true; }

Error: Cannot find module './lib/ReactPropTypesSecret'
I am running npm start and keep getting this error, tried updating the npm as seen on similar posts, but no luck. Current version is 6.5.0. was working on the same file 12 hours ago and all was working fine.
Failed to compile. ./src/index.js Error: Cannot find module './lib/ReactPropTypesSecret' Referenced from: /Users/igorpavlenko/Desktop/projects/react/marwan30/php_react/marwan/package.json

https in node js using express
I am using express and i want to load ssl certificates in my app to make it run in https
I have loaded by angular app using
app.use(express.static(path.join(__dirname, 'public/zibteksales')));
i am not getting the options to pass certificates
var options = { key: fs.readFileSync('test/fixtures/keys/agent2key.pem'), cert: fs.readFileSync('test/fixtures/keys/agent2cert.cert') }; https.createServer(options, app).listen(app.get('port'));
so, what is the proper way to load ssh in node that runs angular app with express static

Recommendation for approach regarding How to Dial multiple outbound calls and assign them to specific Agents through a Call Manager
I've been working with twilio for providing calling solution in Node.js. I need a suggestion in captioned scenario. At high level I want to develop a call manager that is able to dial multiple calls to clients depending upon availability of available agents. Say 10 agents are available now so the call manager fetch list of 10 customers and dial call to them and once connected the call is transferred to one of the 10 agents and so on. Need suggestion how to implement the feature and what twilio APIs to use to achieve the task.

I want to design a website where I want to browse and upload my ubuntu folder with various editing?
I want to design a website where I want to browse and upload my ubuntu folder with various editing functionalities. Would you please tell me how can start I am not getting any idea? how I will fetch the folder and how I will upload I don't have any idea also after any changes it will change in my ubuntu system itself.Thanks.

Algorithm to organize a matrix so that neighbors are closest
Here is my problem :
I would like to organize N positive integers into an AxB matrix, so that the difference between neighbor cells is minimized. N is greater than AxB so I have a lot of possible choices.
For example, if I have the numbers 1,3,4,9,21 to position in a 2x2 matrix,
I can build this matrix :
5 4 1 9
we can calculate the sum of the difference between neighbor cells : (54) + (51) + (94) + (91) = 1+4+5+8 = 18
but if I rearrange the numbers this way :
1 4 5 9
the sum is now (51)+(41)+(95)+(94) = 4+3+4+5 = 16 which is better.
I though of using brute force, by switching each number and calculating the sum each time, but my actual problem has a 4*5 matrix and 41 numbers to choose from so the number of possible matrices is 41!/20! (654 764 331 820 982 885 260 361 465 856).
Does anyone have an idea of how to address the problem differently ?

how to find upper bound (high) for binary search?
Suppose a variable 1<=h<1e9 Here 1e9 is the max value of h that test case can have but suppose in a test case where we want to apply binary search with h=100,for some predicate p That is we want to apply binary search in the range of 1 to 100 for some predicate p;
And we know answer may be close to 100,than what is the correct choice of high high=100 or high=1e9
I am asking this question because the problem was this bananas and in the solution he has assigned the upper bound as 1e9 for all the test cases and we know that the max value of h in many of the test cases can be only 5 ,10 ,100 or 500 here is the solution banana solution

Container Packing
I recently came across an interview question asked by Amazon and I am not able to find an optimized algorithm to solve this question:
Goods are packed by set of machines. After packing is done packs are push to belt.
belt is filled right to left. Some lines of belt is empty and some lines are empty. 5 is the Maximum number of goods in line of belt.
Your task is to make machine that increase the efficiency of final packing. For that you need to fill the empty spaces of front lines of the batch of that belt. There is few things you need to consider when moving
 Move backward line to the front if there are enough space for whole line.
 Maximum number of goods for the line is 5
Example input: 3 2 4 output: 5 4 0
Can anyone give algorithm to this.

Finding shortest path (backtracking)
I need help with my homework in backtracking. They asked us to create a function called int ShortestPath(int roads[N][N]);
the function takes a matrix of roads/paths, NxN, (N is defined as 4) The matrix contains integers in the following way: the element (i,j) in the matrix is equal to the length of the path from house i to house j (not vise versa), if the path is possible. if there's no way to get from house i to house j it would be equal to 1. the path length is a positive integer. every element in the diagonal of the matrix is always zero (since every house is far away from it self 0 km). The matrix is not necessarily symmetric.
The function returns the shortest possible path that starts with house number 0 and ends with house number 0, and passes other houses only once. if there's no possible path the function has to return 1.
I've already tried a lot and something in the function is not working
int ShortestFullPath(int roads[N][N]) { return find_min_len(roads, 0, 0, 0); } int find_min_len(int roads[N][N], int i, int houses_passed, int path_len) { if(houses_passed==N1) { return path_len; } int temp_roads[N][N]={{0}}; copy_matrices(roads, temp_roads); if(houses_passed<0) update_col(roads, i, houses_passed1); for(int j = 0 ; j < N ; j++) { if(roads[i][j]<=0) { path_len=0; continue; } int temp = find_min_len(roads, j, houses_passed1, roads[i][j]); if(temp>0) path_len=temp+roads[i][j]; copy_matrices(temp_roads, roads); } if(path_len>0) return path_len; return NO_PATH; } void copy_matrices(int source[N][N], int destination[N][N]) { for( int i = 0 ; i < N ; i++ ) for( int j = 0 ; j < N ; j++ ) destination[i][j]=source[i][j]; } void update_col(int roads[N][N], int j, int houses_passed) { for( int i = 0 ; i < N ; i++) { roads[i][j]=houses_passed; } }
some example for tests: enter the roads 4X4 matrix:
0 2 1 2 1 0 2 1 1 1 0 2 2 1 1 0
The shortest path: 6
and also: enter the roads 4X4 matrix:
0 1 1 3 1 0 1 1 1 1 0 1 2 1 1 0
The shortest path: 5

TSP problem in C using simple backtracking Solution
I was trying to solve the travel salesman program im stuck at the recursive part of moving from one city to another.
Sample input & output:
Please enter the roads 4X4 matrix row by row: 0 2 1 2 1 0 2 1 1 1 0 2 2 1 1 0 The shortest path is of length: 6
Main Objective
each number at the matrice roads[N][N] (currently N=4) is the distance as following: location (i,j) the number represents distance from city i to city j. and the objective is to get from city number 0 (line 0 in matrice) through all cities back to city 0 at shortest path.
My Solution Create a shell function ShortestFullPath() with all first parameters. and seconed backtracking function short_path where i check stopping conditions (such as same city => 0 or no city => 1 or finished going through all cites)
A array visited is as the size of number of cities. each city I visit, I flag the matching index in the array as true or false, and check all options in the city to other cities.
Side Notes
checkvisited() checks if array visited is all true;
min() checks minimun between current_path and the best path so far.
int ShortestFullPath(int roads[N][N]) bool visited[N]; for(int i = 0; i < N; i++) { visited[i] = false; } int shortest_path = 9999; int current_path = 0; int city = 0; int j = 0; //destinaton city visited [0] = true; if(short_path(roads, city, j, current_path, &shortest_path, visited)) Print(shortest_path); else Print(NO_PATH); return 0; bool short_path(int roads[N][N], int city, int j, int current_path, int *shortest_path, bool visited[N]) { if(check_visited(visited)) { *(shortest_path) = min(current_path, *shortest_path); current_path = 0; return true; } if((roads[city][j] == 1) (roads[city][j] == 0)){ return false;} if(visited[city] == true) return false; visited[city] = true; current_path = current_path + roads[city][j]; for(int j =0; j< N; j++) { short_path(roads, city, j, current_path, shortest_path, visited); } visited[city] = false; return true; }

NQueen Beginner Backtracking
To practice what I've learned about backtracking algorithms, I'm trying to solve the NQueen problem.
I've written some functions to check if a move is legal, but I can't see how to implement those using backtracking.
bool manger_ligne (int a[][4],int i) { for (int j=0;j<4;j++) { if (a[i][j] == 1) return false ; } return true; } bool manger_col (int a[][4],int j) { for (int i=0;i<4;i++) { if (a[i][j] == 1) return false ; } return true ; } bool isTrue (int a[][4],int i,int j,int k) { if (k==0) { return 1; } if (i > 3 && j > 3) { return 0; } if (manger_diagonal(a, i, j) == true && manger_col(a, j) == true && manger_ligne(a, i) == true) { a[i][j] = 1; if (isTrue(a, i, j+1 ,k) == true) { if (isTrue(a, i+1,j ,k) == true) //backtracking problem return true; } a[i][j] = 0; } return false ; }