Given an array A, its binarian(A) is defined as 2^A[0] + 2^A[1] + …. 2^A[n]; Questions asks to find anther shortest array B whose binarian(B) is same as A’s. For example, A=[1,0,2,0,0,2],thus if B=[3,2,0], this satisfies the requirements, and the output is 3. Could you guys provide some ideas of how to solve this problem? Thanks. Answer Here’s a solution
Tag: algorithm
Knight’ tour using Warnsdorff’s rule gives wrong output with odd sizes mostly
I wrote a code to solve the knight’s tour problem, the problem is that sometimes it gets the wrong output. In particular, very frequently with odd sizes of the board: For example starting at position [0,1] and with a board 5X5 it gives me: As you can see there’s a repetition of [2,3]. I checked out how many wrong outputs
Snail Algorithm – controlling Max/Min position for traversal
I’m working on a problem in CodeWars for fun, and I’m having trouble with a couple of things: Understanding where I need to modify the code in order to properly control the “turning point” of m and n so that they begin decreasing rather than increasing. Refactoring this code appropriately. The purpose of the algorithm is to traverse a 2D
Finding Subarrays of Vowels from a given String
You are given a string S, and you have to find all the amazing substrings of S. Amazing Substring is one that starts with a vowel (a, e, i, o, u, A, E, I, O, U). Input The only argument given is string S. Output Return a single integer X mod 10003, here X is number of Amazing Substrings in
How to calculate nucleus amount of cell?
I am using Python 3.5 and OpenCV 3 to analyze pictures of cells in biology. My pictures look like this: I want to be able to calculate a ratio of the area of the cell’s nucleus to the area of the cell as a whole. In my slides, the nucleus is dark purple and other regions of the cell are
Shortest Time Remaining Next (STRN) Scheduling
Another user posted this question on Shortest Job First (SJF). Here’s the example: How would this be solved for Shortest Remaining Time Next? The preemptive version of Shortest Job First. I understand that the process with smallest amount of time remaining until completion is selected to execute. However, what happens if a new process arrives that has a burst time
How to find nth Fibonacci number using Javascript with O(n) complexity
Trying really hard to figure out how to solve this problem. The problem being finding nth number of Fibonacci with O(n) complexity using javascript. I found a lot of great articles how to solve this using C++ or Python, but every time I try to implement the same logic I end up in a Maximum call stack size exceeded. Example
deceptively simple implementation of topological sorting in python
Extracted from here we got a minimal iterative dfs routine, i call it minimal because you can hardly simplify the code further: Here’s my question, how could you transform this routine into a topological sort method where the routine also becomes “minimal”? I’ve watched this video and the idea is quite clever so I was wondering if it’d be possible
List of all classification algorithms [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 28 days ago. The community reviewed whether to reopen this question 28 days ago and left it closed: Original close reason(s) were not resolved Improve this
Google foobar gearing_up_for_destruction
I was doing the google foobar challenge but ran out of time on the following challenge i am trying to see what i did wrong. Challenge As Commander Lambda’s personal assistant, you’ve been assigned the task of configuring the LAMBCHOP doomsday device’s axial orientation gears. It should be pretty simple – just add gears to create the appropriate rotation ratio.