Showing posts from September, 2014

Setting Java to 1.6 after installing 1.7

I have JDK 1.6 installed on my machine. Then I installed JDK 1.7 and I ran the command "java -vesion" to check which version that my machine points to. The result was 1.7 version. I checked my PATH environment variable and it was pointing to the 1.6 version!
The problem was in the java.exe in under C:\Windows\System32. It was pointing to the 1.7. After deleting it, my machine default one is 1.6.

Another Codility task

Bellow is a Java implementation for a solution of the CountDistinctSlices problem that you can find under tasks the Caterpillar method lesson through this link This solution has 100% correctness and it suffers in the performance as it is 40%.

import java.util.ArrayList; import java.util.HashSet; import java.util.List; public class Solution { public int solution(int m, int[] a) { if(a.length >= 1000000000) { return a.length; } int cursor = 0; int count = a.length; HashSet check = new HashSet(); List temp = new ArrayList(); for(int y : a) { if(y>m) { continue; } temp.add(y); } a = new int[temp.size()]; int i = 0; for (Integer e : temp) a[i++] = e.intValue(); for(int y = 0 ; y < a.length ; y++) { if(check.add(a[y])) { if(check.size() == 1) continue; count++; if(y+1 == a.length) { check.clear(); cursor++; y=cursor-1; } } els…

Develop your skills with Codility

As a programmer, is a good tool that provide the programmers and developers a good chance to develop their programming skills. It provides programming lessons, readings and monthly interesting challenges for problems to solve in many programming languages such as Java, C#, C and others.
I believe that all of us should keep an eye on such arithmetic and mathematical problems that depends on the way you implement them using your preferred programming language so you can implement them correctly and efficiently. Beside considering the scientific evaluation for your code through considering time and efficiency complexity. This would help refreshing our minds in the way we implement different business problems and requirements in a way or another.
I have gone through some of its lessons that you can find in this link beside the readings they provided with the lessons. Each lesson contains some tasks that you can go through them to tes…