I am solving Codility problem CountSemiprimes: Count the semiprime numbers in the given range [a..b]. Task description A prime is a positive integer X that has exactly two distinct divisors: 1 and X. The first few prime integers are 2, 3, 5, 7, 11 and 13. A semiprime is a natural number that is the product of two (not necessarily
Tag: algorithm
Knight tour problem – order of moves affect performance
I was trying to implement a solution for knight tour problem. I faced an interesting issue. I would like to know the reason for the behavior. This is the code – it works fine. Now we could run this, starting with knight position as (2, 2) in the matrix When i tried to run the starting position as (0, 0)
How multiple recursion works? [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 3 years ago. This post was edited and submitted for review 4 months ago and failed to reopen the post: Original close reason(s) were not resolved Improve this question I need
Java Staircase is printing in wrong direction (hackerrank)
This solution to the staircase prints the correct output, but in the opposite direction. Any idea how to alter this solution to get the desired result? Input: Expected output: Actual Output: It’s for a hackerrank easy challenge. I just want to be able to use my approach that I discovered instead of a solution I find online. Thanks! Answer You
Count the minimum number of jumps required for a frog to get to the other side of a river
I work with a Codility problem provided below, The Fibonacci sequence is defined using the following recursive formula: A small frog wants to get to the other side of a river. The frog is initially located at one bank of the river (position −1) and wants to get to the other bank (position N). The frog can jump over any
Benders.Strategy using Java and opl
I’m solving a mathematical model using Java however when i tried to call the Benders Strategy i keep receiving this error: Exception in thread “main” java.lang.IllegalArgumentException: No enum class ilog.cplex.cppimpl.IloCplex$IntParam with value 1501 at ilog.cplex.cppimpl.IloCplex$IntParam.swigToEnum(IloCplex.java:1974) at ilog.opl.IloCplex.setParam(IloCplex.java:5640) Here’s a part of my code in Java (i’m using CPLEX 12.8 and the library oplall.jar) : Answer There’s a similar question here.
String compression and decompression for data set that can be nested
My input is a compressed string of the format number[string] and the decompressed output form should be the string written number times. For example: My brute force approach in Java: Can I get some better approach with less cost? Answer We actually want to find the strings in [] and repeat it n times which is specified before the [].
More recursive method to print Pascal’s triangle
I’ll try to use a recursive method to print pascals triangle to the standard output. I started by making an iterative method to get an idea of how I wanted the method to work. See the code below. Javadoc and the signature of binom Then i began to work on the recursive method. I can not use any class variable
Inserting a node at a specific position in a Linked list
I am given the pointer to the head node of a linked list, an integer to add to the list and the position at which the integer must be inserted. After inserting this node at the desired position I need to return the head node. The code that I have written is not working for some reason and goes in
Need explanation for algorithm searching minimal large sum
I’m solving Codility questions as practice and couldn’t answer one of the questions. I found the answer on the Internet but I don’t get how this algorithm works. Could someone walk me through it step-by-step? Here is the question: And here is the solution I found with my comments about parts which I don’t understand: Answer So what the code