so i took the codility interview test yesterday and was informed today that i failed, unfortunately i wasnt given any other information by either codility nor the employer as to where i screwed up so i would appreciate some help in knowing where i went wrong. i know codility pays alot of emphasis on how fast the program runs and
Tag: algorithm
Java – Collections.sort() performance
I’m using Collections.sort() to sort a LinkedList whose elements implements Comparable interface, so they are sorted in a natural order. In the javadoc documentation its said this method uses mergesort algorithm which has n*log(n) performance. My question is if there is a more efficient algorithm to sort my LinkedList? The size of that list could be very high and sort
How to find second largest number using Scanner and for loop(no array)
So I can easily accomplish task to find largest number and then if can be divided by three, print out. But do not know how to find second largest number from users sequence. Thanks for any hints! Answer
Running out of java heap space- 15 puzzle problem
G’day all, I tried the solution for eight puzzle problem posted here by joel Neely and played around with it and modified it so that can be used to solve for higher grids[Changed the String representation of the grid to two dimensional integer representation and modified the logic accordingly]. However the modified code can solve the 3×3 grids but quickly
Iteratively compute the Cartesian product of an arbitrary number of sets
I want to compute the cartesian product of an arbitrary number of nonempty sets in Java. I’ve wrote that iterative code… public static List<Set> cartesianProduct(List<…
How to obtain all subsequence combinations of a String (in Java, or C++ etc)
Let’s say I’ve a string “12345” I should obtain all subsequence combinations of this string such as: –> 1 2 3 4 5 –> 12 13 14 15 23 24 25 34 35 45 –> 123 124 125 234 235 345 –> 1234 1235 1245 1345 2345 –> 12345 Please note that I grouped them in different number of chars
A range intersection algorithm better than O(n)?
Range intersection is a simple, but non-trivial problem. Its has been answered twice already: Find number range intersection Comparing date ranges The first solutions is O(n) and the second solution is for a database (which is less than O(n) of course). I have the same problem, but for a large n and I am not within a database. This problem
Why does Java’s hashCode() in String use 31 as a multiplier?
Per the Java documentation, the hash code for a String object is computed as: using int arithmetic, where s[i] is the ith character of the string, n is the length of the string, and ^ indicates exponentiation. Why is 31 used as a multiplier? I understand that the multiplier should be a relatively large prime number. So why not 29,