algorithm

Degenerate root finding problem: get the first value for which f(x)>0

Degenerate root finding problem: get the first value for which f(x)>0 Question: Given a function f(x) that is zero for all values x less than a critical value c, and non-zero for values x>c. I want to approximate the critical value c using an optimization method. Because the function f(x) is expensive, I want to …

Total answers: 2

A* algorithm in python having trouble with making the final path

A* algorithm in python having trouble with making the final path Question: Full now working Code: https://docs.google.com/document/d/1j1BLe4L735nmXWR0Vnj3TeHumzI5x7Ea5yWJSc5j-8w/edit I tried to code the A* pathfinding algorithm and I got it to expand in the right way using the g and h costs. It looked really cool, however when I tried finding the final path by using …

Total answers: 1

Finding all possible sums of three integers within a list

Finding all possible sums of three integers within a list Question: I need to use a list of perfect cubes to find all possible sums of three different numbers within that list. The sum must also be a perfect cube. My original solution was to nest 3 for loops to cover each number, but this …

Total answers: 2

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