anudeepreddy
BAN USERJava Code:
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
public class HighestValue {
public static void main(String[] args) {
// TODO Auto-generated method stub
String input[]=new String[]{"9","918","917"};
//String input[]=new String[]{"1","112","113"};
//String input[]=new String[]{"8","991", "89", "51", "5", "0"};
List<String> ls=new LinkedList<String>();
//ls.add(input[0]);
for(int i=0;i<=(input.length-1);i++){
int index=0;
Iterator it=ls.listIterator();
while(it.hasNext()){
String element=(String)it.next();
String str1=element+input[i];
String str2=input[i]+element;
if(str1.compareTo(str2)>0)
index++;
else
break;
}
ls.add(index, input[i]);
}
Iterator it1=ls.listIterator();
while(it1.hasNext()){
System.out.print(it1.next());
}
}
}
I used Linked List data structure in above code. TimeComplexity is O(n^2)
import java.util.Arrays;
class Coordinate implements Comparable<Coordinate>{
int x;
int y;
Coordinate(int x,int y){
this.x=x;
this.y=y;
}
public int compareTo(Coordinate e2) {
int x=((Coordinate)e2).x;
return this.x-x;
}
}
public class TimeInterval {
public static void main(String[] args) {
// TODO Auto-generated method stub
Coordinate[] c=new Coordinate[4];
c[0]=new Coordinate(1,3);
c[1]=new Coordinate(5,7);
c[2]=new Coordinate(2,4);
c[3]=new Coordinate(6,8);
Arrays.sort(c);
boolean set=false;
for(int i=0;i<3;i++){
if((c[i].y)>(c[i+1].x)){
set=true;
//System.out.println("overlap");
}
}
if(set){
System.out.println("overlap");
}else{
System.out.println("Not overlap");
}
}
}
Time complexity:O(nlogn)
I will be using stack.
{-->push to stack
{--->push to stack
}--->check in top of stack whether character '{' is present or not.if present pop it out.if it is not present return false
follow similar steps for '[',']','(',')'
after processing enter string if you find stack is empty then brackets are balanced.
head -n 1 game.txt > game1.txt(first line of file)
tail -n 1 game.txt > game2.txt(last line of file)
head -n 3 game.txt > game1.txt (This commmand gives first 3 lines of txt file)
tail -n 3 game.txt > game2.txt(This command gives last 3 lines of txt file)
Node* first=root;
- anudeepreddy December 10, 2015Node* second=root;
Node* prev=null;
while(second.link!=null){
prev=first;
first=first.link;
second=second.link;
if(second.link!=null)
second=second.link;
else{
printf(prev);//printing middle two nodes for even number of nodes present
printf(first);
}
}
printf(first);// printing middle node for odd number of nodes in list