Jay
BAN USER
Comments (3)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
Formatted code:
public class MinMax {
public static void main( String args[] ){
int[] array = { 1,2,3,4,5,6,7 };
Arrays.sort( array );
int minMaxArray[] = new int[ array.length ];
for( int index = 0, firstPos = 0, lastPos = array.length - 1; index < array.length;index++ ){
if( index % 2 != 0 ){
minMaxArray[ index ] = array[ firstPos ];
firstPos++;
}
else {
minMaxArray[ index ] = array[ lastPos ];
lastPos--;
}
}
System.out.println( "Input:" + Arrays.toString( array ) );
System.out.println( "Output:" + Arrays.toString( minMaxArray ) );
}
}
Comment hidden because of low score. Click to expand.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
The stable marriage problem has been stated as follows:
- Jay February 25, 2016Given n men and n women, where each person has ranked all members of the opposite sex in order of preference, marry the men and women together such that there are no two people of opposite sex who would both rather have each other than their current partners. When there are no such pairs of people, the set of marriages is deemed stable.