shashi kumar
BAN USERpackage com.eb.corealgo;
public class AfterBiggest {
public int[] getNextBigCount(int [] input){
int l=input.length;
int output[]=new int[l];
for(int i=0;i<l;i++){
int c=input[i];
int co=0;
for(int j=i;j<l;j++){
if(input[j]>c){
co++;
}
}
output[i]=co;
}
return output;
}
public static void main(String args[]){
AfterBiggest big=new AfterBiggest();
int inp[]={5,3,9,8,2,6};
int out[]=big.getNextBigCount(inp);
for(int i:out){
System.out.println(i);
}
}
}
package com.eb.corealgo;
public class Toepliez {
public boolean isToepliez(int matrix[][]){
boolean isTpepliez=false;
try{
int rows=matrix.length;
int col=1;
int startElement=matrix[0][0];
for(int i=1;i<rows;i++){
int nextElement=matrix[i][col++];
if(nextElement==startElement){
startElement=nextElement;
if(i==rows-1){
isTpepliez=true;
}
continue;
}else if(i==rows-1){
break;
}
}
}
catch(Exception e){
e.printStackTrace();
}
return isTpepliez;
}
//test app
public static void main(String args[]){
Toepliez tz=new Toepliez();
int matrix[][]={
{6,7,8,9,2},
{4,6,7,8,9},
{1,4,6,7,8},
{0,1,4,6,7}
};
System.out.println(tz.isToepliez(matrix));
}
}
package com.eb.corealgo;
public class MatrixPrint {
public String printreverse(int mat[][]){
String res="";
if(mat==null){
throw new NullPointerException("Null MAT");
}
int rows=mat.length;
int cols=mat[0].length;
boolean isPrint=true;
int row=0;
while(isPrint){
if(row<rows){
for(int i=0;i<cols;i++){
if(row%2==0){
res+=mat[row][i]+" ";
}
else{
res+=mat[row][cols-i-1]+" ";
}
}
row++;
}
else{
break;
}
}
return res;
}
//test app
public static void main(String args[]){
int matrix[][]={
{1,2,3,4,5},
{6,7,8,9,10},
{11,12,13,15,16}
};
MatrixPrint matPrint=new MatrixPrint();
System.out.println(matPrint.printreverse(matrix));
}
}
public static int search(int arr[],int first,int last,int key)
{
while((last>0)&&(first<=last))
{
int mid=(first+last)/2;
if(arr[mid]==key)
{
return mid;
}
else if(arr[mid]>key)
{
last=mid-1;
return(search(arr,first,last,key);
}
else
{
return(search(arr,mid+1,last,key);
}
}
- shashi kumar November 14, 2016