I have two lists of marks for the same set of students. For example: If I accept only students above a threshold according to list A then I can look up their marks in list B. For example, if I only accept students with at least a mark of 80 from list A then their marks in list B are

# Tag: algorithm

## Geometric series: calculate quotient and number of elements from sum and first & last element

Creating evenly spaced numbers on a log scale (a geometric progression) can easily be done for a given base and number of elements if the starting and final values of the sequence are known, e.g., with numpy.logspace and numpy.geomspace. Now assume I want to define the geometric progression the other way around, i.e., based on the properties of the resulting

## Subset algorithm behaves differently in Python than C++

The algorithm follows recursive approach, dividing the array in two parts: In first recursion the first part is neglected In second part the first part is added Code for C++ (Works Fine) Code for Python Answer In the C++ version, res is a by-value parameter, so a copy of the vector is made in each call. Python passes references to

## Check substring with 1 character difference in python

I have list of thousand of strings sub_strings, and list of millions of strings strings I want to check if strings[i] have substring from sub_strings or substring that’s different in 1 character expected Answer Here’s a route for solving: That will spit out [True, True, True, True, False, True] But this is going to get very slow as you add

## Finding a next lowest number from a List in python

I have a list of arrays as follows: Array =[3, 6, 5, 7, 2, 4, 3, 5, 4, 5, 4, 7, 6, 7, 1, 7, 4, 6, 3] example: Value = 3, 6, 5, 7, 2, 4, 3, 5, 4, 5, 4, 7, 6, 7, 1, 7, 4, 6, 3 valley/Peak = v, p, v, p, v, p, v, p,

## Interval insert by exclusively adding an interval to a list of intervals

This is similar to this problem: https://leetcode.com/problems/insert-interval/ However, what I need is a bit different. I need to lower the smallest interval by 1 if to compare with the one I want to add and increase the next closest interval by one to with the one I want to add if there are intersections. Say I have: intervals: [0, 3],[4,

## What is the time complexity of a bubble sort algorithm applied n times to the same array?

I had this question on a test and i’m trying to understand it: What is the time complexity of this function (in the worst case) assuming that Bubblesort() is the most optimized version of the Bubble Sort algorithm? The options were: Linear Quadratic Cubic I was thinking that the first sort (because it’s the worst case) would be O(len(a)^2) and

## how to return truth value to the “base function” in recursion?

my function looks like this: here, when we return True or False, the return value of the previous recursive call is not affected. What I want to do is: if a recursive function returns True, the “base case function” should also return True immediately A workaround I’ve found is using a nonlocal variable: but I was wondering if there was

## Power Plant – solve the problem in O(nlogn)

I had the following problem on the exam: A certain power plant needs coal to operate, so it has ordered n deliveries, and information about each delivery (number of tons) is stored in a list A. The delivered coal is stored in warehouses with consecutive numbers 0, 1, …. (Their exact number is not given). Each warehouse has the same

## Recursion ( kind of sub-set sum, but not exactly ) – True if can buy pens at exact price, else False

I have this question: you have a list of [7,9,11] pens. you have a function: you need to check whether or not if you can buy the exact amount. for example, I have X=23 I can buy 1*9, 2*7 I just need to return True if it is able, false else. I saw the answer, they did it brute force