codedore
BAN USER// here's o(n log n) using heap sort.
public static void orderElements(int [] valueArray,int[] indexArray){
buildheap(valueArray,indexArray);
int n = indexArray.length-1;
for(int i= n ;i>0;i--){
swap(indexArray,0, i);
swap(valueArray,0, i);
n=n-1;
maxheap(valueArray, indexArray, 0,n);
}
}
private static void swap(int[] array, int i, int j) {
if (i == j)
return;
array[i] ^= array[j];
array[j] ^= array[i];
array[i] ^= array[j];
}
public static void buildheap(int[] valueArray,int[] indexArray) {
int n = indexArray.length - 1;
for (int i = n / 2; i >= 0; i--) {
maxheap(valueArray,indexArray, i,n);
}
}
public static void maxheap(int[] valueArray,int []indexArray, int i, int n) {
int largest;
int left = 2 * i;
int right = 2 * i + 1;
if (left <= n && indexArray[left] > indexArray[i]) {
largest = left;
} else {
largest = i;
}
if (right <= n && indexArray[right] > indexArray[largest]) {
largest = right;
}
if (largest != i) {
swap(indexArray,i, largest);
swap(valueArray,i, largest);
maxheap(valueArray,indexArray, largest,n);
}
}
public static class Point implements Comparable<Point> {
public int x;
public int y;
public Point(int x , int y){
this.x = x;
this.y = y;
}
@Override
public int compareTo(Point o) {
// TODO Auto-generated method stub
return x - o.x;
}
public String toString(){
return "["+x+","+y+"]";
}
}
public static int getMaxOverlappingIntervals(List<Point> points) {
// sort the points with ascending start order.
Collections.sort(points);
int result = 0;
Point maxPoint = new Point(points.get(0).x,points.get(0).y);
String overlaps = " [" + points.get(0).x + "," + points.get(0).y + "]";
for (int i = 1; i < points.size(); i++) {
if (maxPoint.y > points.get(i).x) { // overlap
maxPoint.y = Math.max(points.get(i).y,maxPoint.y);
overlaps += " [" + points.get(i).x + "," + points.get(i).y + "]";
result++;
} else {
maxPoint.y = points.get(i).y;
maxPoint.x = points.get(i).x;
}
}
if ( result == 0 ){
System.out.println(" overlaps : " + 0);
}else{
result++;
System.out.println(" overlaps : " + overlaps);
}
return result;
}
RepKinsleyJames, Network Engineer at Accenture
I graduated from College with a master’s degree in arthrogryposis. After graduation I am working as a manager in ...
Reploreleijhansen, Aghori Mahakal Tantrik at ABC TECH SUPPORT
I am Lorelei.I am working in a store as a Bonus clerk promoting the development, and implementation and solutions ...
Repberrysvickers, Associate at Absolute Softech Ltd
Spent 2001-2004 developing strategies for country Luxury Car Rental Miami. Had some great experience building robots for the underprivileged. Have ...
Repstacimdalton, Dev Lead at ASAPInfosystemsPvtLtd
At the moment I'm implementing Slinkies in the financial sector. My current pet project is researching break up a ...
RepGenesisCruz, Integration Software Engineer at NetApp
I am a highly professional and experienced board director with many years of experience leading non-profit as well as for-profit ...
won't work.
- codedore April 26, 2014"bcd" hash is 'b'+'c'+'d' = 98+99+100 = 297
"ace" hash is 'a'+'c'+'e' = 97+99+101 = 297