Skip to content

Tag: algorithm

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

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