This is the algorithm of this problem: Write a function that takes two arrays as input, each array contains a list of A-Z; your program should return True if the 2nd array is a subset of 1st array, or False if not. Answer The complexity of your algorithm is O(n*k), where n and k is length of arrays. You have
Tag: algorithm
Is there a O(n) way to find the most repeated item in list without using counter
I need a solution that is O(n) for finding most repeated element in a list. If 2 or more numbers are repeated the same amount of time return smallest number. Output should be 4 which should give the count of 3 Answer You could use max and groupby: Or use a dict as a counter: Or if your data has
Sticky index reference while inserting into 2D list in Python
While attempting to implement a function that produces all permutations given a list of integers, I’m seeing this behavior where the inserts are not occurring as expected. My code: When calling permute([1, 2, 3]) I’m expecting the perms to grow like: However, by the second iteration of the interior loop with new_perms: [[1], [1]] I’m expecting it to grow to
How to go back a character in a string in Python
What I’m trying to figure out is how to go back a position in a string. Say I have a word and I’m checking every letter, but once I get to a “Y” I need to check if the character before was a vowel or not. (I’m a beginner in this language so I’m trying to practice some stuff I
What is the Time Complexity of this code sample? like nested loop, but inner loop is a fixed number
m, n are two python array inner loop is maximum 3 Thinking O(n)? because inner looping is in a fixed amount O(n*m)? O(n*3)? this is not the correct way :( What is the correct O time complexity for this? Answer Time complexity of the statement inside the inner loop is in O(1). Because, it is just only one comparison and
How to make custom hash function for hashing matrix (Othello board) to number
I have to do project for which I need custom function for hashing matrix. Project is about Othello (Reversi) game which means that I need to hash fixed 8×8 matrix. This is how initializing matrix looks like: Here is one example of how board looks: As you can see, one player is 1 (which is always me) and the second
Rotating the left the subtrees in an AVL Tree in python
A bit of a newbie to computing science. I have the basics for a binary tree in Python and I was studying some of the applications in an AVL tree: One of the challenges I’m trying to solve is to rotate the left side of a tree in a function that takes the root as a parameter, but I’m getting
Return minimum “sub-DAG” generated from dictionary
I have an input data and some transformation functions t1, t2, t3, t4, t5, t6. Each of them requires some columns as input and outputs some columns. The DAG associated with these transformations is I get as input the columns I want to generate and I should return the sub-DAG required to obtain it (I am not interested only in
All possible combinations of numbers with rounding error matching sum
I have encountered one problem that I struggle to solve. There is a group of numbers that should match some given sum and the function should output all possible combinations. The length of the input numbers differ, might be 3 or sometimes 20 numbers in the input array. Unfortunately, some numbers do have a rounding error and some do not
CodeJam 2021 Qualifier Round Moons and Umbrellas Algorithm Explanation
I was trying to understand the solution to the codejam problem mentioned by the title. Specifically the third part for “extra credits”. This is the solution by “kamyu104” from Github. The programming problem in a nutshell is given a string of C’s and J’s, for example, CCJCJ??JC or JCCC??CJ, the question marks should be replaced by either C or J.