Category "algorithm"

How to calculate multi-operator of list in dart?

I have a list of num and string of operator above: final List<dynamic> items = [5.0, "-", 2, "*", 3]; I want to calculate the value inside of it. I can d

Coursera DSA Algorithmic toolbox week 4 2nd question- Partitioning Souvenirs

Problem Statement- You and two of your friends have just returned back home after visiting various countries. Now you would like to evenly split all the souveni

Trouble simplifying conditional

I'm having trouble simplifying a conditional statement. It looks like this: There is an array of arrays like this, dice = [ [a, b], [c, d] ]. a, b, c, and d rep

k-diff sequences in a float array

Looking for an algorithm to find longest sequences (pairs, triplets, up to quadruplets) that are separated by a constant, non-integer difference k in a sorted a

Time complexity of nested loop?

I'm not very familiar with Big O notation. I'm wondering does the time complexity of the nested loop always be n^2? For example the following function, the inne

How to implement a "reverse" BFS algorithm?

I'm playing a game with the following rules: There is a map (with walls), some coins (randomly generated in the map) and a Minotaur. The goal is to grab as many

Find sorting algorithm for an elevators floor travel schedule, starting from the current floor with preselected floors to reach and a travel direction

I'm making an elevator in react, But I need to make a function that sorts an array to the nearest to the number X and also there is a condition if the elevator

Hungarian Algorithm Constraint using Python

I have dataframe of job and employee, with the duration each employee can finish each job. I want to use Hungarian algorithm to assign each job to 1 employee, a

Deep find object in tree, then return object and the path to it through the tree

I've written a recursive function to find a given object and the path within that tree, but when I change the target id (over here : if(tree.targetModuleId ===

Music Chairs problem implementation in C++

I am currently practicing algorithms and DS. I have stumbled upon a question that I can't figure out how to solve. So the question's link is there: In summary,

Which data structure can act like a circular queue?

The picture above has 25 action points such that: Each of the four corners of each of the three layers is an action point. The midsection of each of the four s

Big(O) time complexity unable to find

What is time complexity of following code : int count = 0; for (int i = N; i > 0; i /= 2) { for (int j = 0; j < i; j++) { count += 1;

A problem was caused by an array that was not initialized

I am trying to solve a execise, which amis to find the Last Digit of a Large Fibonacci Number, and I try to search for others' solution, and I find one here: h

How to get original array from random shuffle of an array

I was asked in an interview today below question. I gave O(nlgn) solution but I was asked to give O(n) solution. I could not come up with O(n) solution. Can you

Minimum moves to transform a list so that each element equals its own frequency

Given a sorted array like [1,2,4,4,4]. Each element in the array should occur exactly same number of times as element. For Example 1 should occur 1 time, 2 shou

How to convert an XML structured-like object to a JSON string in Java?

So I have an XML structured object (Java) and need some help to convert it to a JSON string without using any library and in an iterative way. E.g <root>

Adding all elements of an array except the element at index with O(n) complexity

This is what i came thru a problem in some coding test. problem statement was like that we have to add all the elements of an array except the element at the i

How to I make my AI algorithm play 9 board tic-tac-toe?

In order to make it easy for others to help me I have put all the codes here https://pastebin.com/WENzM41k it will starts as 2 agents compete each other. I'm t

How do I check if an array includes a value in JavaScript?

What is the most concise and efficient way to find out if a JavaScript array contains a value? This is the only way I know to do it: function contains(a, obj) {

Finding performance feasibility using array strings

Here is the requirement details: time = ["09-13", "12-14"] getResult(time) = false The first performance runs from 9 a.m. to 1 p.m. and the second one starts