Skip to content
Advertisement

Tag: algorithm

python – prefix sum algorithm

I am trying to grasp the idea behind the prefix sum concept looking at the example presented in the Prefix Sum Lesson by Codility here (The mushroom picker problem) My understanding is that the whole concept is based on the simple property where for finding a sum of all elements between two positions A(pos_left, pos_right) of an array A a

Python program to check matching of simple parentheses

I came across this exercise of checking whether or not the simple brackets “(“, “)” in a given string are matched evenly. I have seen examples here using the stack command which I haven’t encountered yet. So I attempted a different approach. Can anyone tell me where I am going wrong? The idea is to pile up “(” and “)”

Extract string inside nested brackets

I need to extract strings from nested brackets like so: Result (Order doesn’t matter): Note, the string could have N brackets, and they will always be valid, but may or may not be nested. Also, the string doesn’t have to start with a bracket. The solutions I have found online to a similar problem suggest a regex, but I’m not

Finding the “centered average” of a list

“Return the “centered” average of a list of integers, which we’ll say is the mean average of the values, except ignoring the largest and smallest values in the list. If there are multiple copies of the smallest value, ignore just one copy, and likewise for the largest value. Use integer division to produce the final average. You may assume that

hexToBinary dictionary

So I am working on this problem: Recall from the Number Systems unit the method for converting hexadecimal numbers to binary by converting each hex digit to its equivalent four binary digits. Write a Python function named hexToBinary with parameters (number, table) that uses this algorithm to convert a hexadecimal number to a (return) binary number. The algorithm visits each

BFS algorithm in Python

Guys! Can someone help me with this bfs code? I can’t understand how to solve this queue line. Answer To extend your queue with all nodes not yet seen on the path, use set operations: or use a generator expression: Lists don’t support subtraction. You don’t really need to filter the nodes, however, your code would work with a simple:

Fast hash for strings

I have a set of ASCII strings, let’s say they are file paths. They could be both short and quite long. I’m looking for an algorithm that could calculate hash of such a strings and this hash will be also a string, but will have a fixed length, like youtube video ids: MD5 seems to be what I need, but

Advertisement