Category "algorithm"

Minimum car required to accommodate given people

I had one coding round where question statement was like this *You have a given number of friends and seating capacity of their cars now you need to find minimu

Generating integers in ascending order using a set of prime numbers

I have a set of prime numbers and I have to generate integers using only those prime factors in increasing order. For example, if the set is p = {2, 5} then my

Daily Coding Problem 260 : Reconstruct a jumbled array - Intuition?

I'm going through the question below. The sequence [0, 1, ..., N] has been jumbled, and the only clue you have for its order is an array representing whether e

dynamic minimum spanning tree

I want to make a dynamic minimum spanning tree. I have an existing MS tree over n vertices and I add one more vertex and edges to all the existing vertices from

algorithm to calculate portfolio weights with negative returns?

Summary Below is the full question (a bit complicated in its full form) here's a super simplified version (which is the heart of what I'm asking). If I told you

Two robots on a line

You probably know the problem with the two robots dropped on a line when you need to program them to meet. Two robots are dropped from an airplane and land

Generating combinations in c++

I have been searching a source code for generating combination using c++. I found some advanced codes for this but that is good for only specific number predefi

Given a number, find the next higher number which has the exact same set of digits as the original number

I just bombed an interview and made pretty much zero progress on my interview question. Given a number, find the next higher number which has the exact same se

Mapping coordinates from plane given by normal vector to XY plane

So, I have this algorithm to calculate cross-section of 3D shape with plane given with normal vector. However, my current problem is, that the cross-section is

How to find the winner(s) of Brazil's Mega Sena lottery most efficiently?

Mega Sena is Brazil's most famous lottery. The number set ranges from 1 to 60 and a single bet can contain each from 6 to 15 numbers selected (the more numbers

Map of sets into list of all combinations

I'm stuck with a simple task. What I want to do is to transform Map<K,Set<V>> into the List<Map<K,V>> getting all possible combinations:

Algorithm to find edit distance to all substrings

Given 2 strings s and t. I need to find for each substring in s edit distance(Levenshtein distance) to t. Actually I need to know for each i position in s what

How to simulate velocity in a falling sand game?

I'm creating a falling sand game and would like to implement velocity so elements can travel in different directions at varying speeds. Games such as Noita use

Squares of a Sorted Array, why sorted() method is faster than O(n) method? [closed]

I am working on leetcode algorithm problem 977. Squares of a Sorted Array. Why the submissions using built-in method sorted is faster than my

Sorting 10GB Data in 1 GB memory. How will I do it?

Here is the problem: I have only 1GB RAM in computer. I have a text file of 10 GB data.This file contains numbers. How will I sort them? Adding some more detai

Unable to convert class syntax to function syntax for a Linked List

Okay so I'm learning Data Structures where my tutorial is following class syntax. So now I am trying to convert it to function declarations as I want to practic

Average transformation matrix for a list of transformations

I have multiple estimates for a transformation matrix, from mapping two point clouds to each other via ICP (Iterative Closest Point). How can I generate the av

Algorithm for finding the fewest rectangles to cover a set of rectangles without overlapping

I have a set of rectangles and I would like to "reduce" the set so I have the fewest number of rectangles to describe the same area as the original set. If poss

Why do we check up to the square root of a number to determine if the number is prime?

To test whether a number is prime or not, why do we have to test whether it is divisible only up to the square root of that number?

Using Big O Notation, what is the correct label for this algorithm?

I am curious. What is the correct way to describe this using Big-O Notation? var prices = [100, 180, 260, 590, 40, 310, 535, 10, 5, 3]; var biggest_profit = 0;