algorithm

Graph DFS – Confused about the return value of recursion

Graph DFS – Confused about the return value of recursion Question: I have a graph where a path from top-left cell – (0,0) to the bottom-right cell – (m-1,n-1) is valid if the difference between consecutive cells are less than or equal to "val". For instance, this example should return true for a val=2 because …

Total answers: 1

Searching for sequence of bits in an integer in Python

Searching for sequence of bits in an integer in Python Question: I have two integers, lets call them haystack and needle. I need to check that, if the binary representation of needle occurred in haystack [and OPTIONALLY find the position of the first occurrence] Example haystack = 0b10101111010110010101010101110 needle = 0b1011001 # occurred in position …

Total answers: 2

ATM cash withdraw algorithm to distribute notes using $20 and $50 notes only

ATM cash withdraw algorithm to distribute notes using $20 and $50 notes only Question: I want to begin by acknowledging that I know there are a ton of similar questions in SO and other websites, but all proposed solutions seem to have the same problem for my specific example. Only using $20 and $50 notes, …

Total answers: 3

Finding maximum difference between each string in an list

Finding maximum difference between each string in an list Question: This was an interview question given to me: Given a list of n strings with length l which at any given index can contain either the character ‘a’ or ‘b’, how would I go about figuring out the maximum difference (meaning the amount of characters …

Total answers: 3

Issue with implementing inverse FFT for polynoms

Issue with implementing inverse FFT for polynoms Question: I am studying the FFT algorithm for fast polynomial multiplication. We went over the algorithm and I decided to try and implement it in Python. from typing import List import numpy as np def fft(p: List[int]) -> List[int]: n = len(p) if n == 1: return p …

Total answers: 1

The max recursion for the coefficient of a polynomial

The max recursion for the coefficient of a polynomial Question: Recently, I came across an interesting counting problem on YouTube posed by 3Blue1Brown-OlympiadLevelCounting. The problem is to find the number of subsets of the set {1, 2, …, 2000} whose elements’ sum is divisible by five. Grant Sanderson presented a beautiful solution, but he also …

Total answers: 2

Fastest Algorithm/Software for MST and Searching on Large Sparse Graphs

Fastest Algorithm/Software for MST and Searching on Large Sparse Graphs Question: I’ve developed a graph clustering model for assigning destinations to vehicle routes, but my implementation is very slow. It takes about two days to process a graph with 400k nodes. My current implementation in Python is as follows: Input data is a sparse graph: …

Total answers: 1

Efficient way to develop a dictionary for reverse lookup?

Efficient way to develop a dictionary for reverse lookup? Question: Let’s say I have a dictionary with the following contents: old_dict = {‘a’:[0,1,2], ‘b’:[1,2,3]} and I want to obtain a new dictionary where the keys are the values in the old dictionary, and the new values are the keys from the old dictionary, i.e.: new_dict …

Total answers: 1

Find all possible sums of the combinations of integers from a set, efficiently

Find all possible sums of the combinations of integers from a set, efficiently Question: Given an integer n, and an array a of x random positive integers, I would like to find all possible sums of the combinations with replacement (n out of x) that can be drawn from this array. For example: n = …

Total answers: 1