Recent Interview Questions
More Questions »Design a File system for windows or linux machine. Use OO concepts.
Q1: Reverse a linked list without using recursion.
Q2: Then reverse every K element of a linked list.
Ans1: I used this method, but when i try and run this back home, I am not able to print the reverse of the linked list even though the function looks good.
It goes on to print the linked list in the same way as it did earlier.Can someone help me understand what is wrong here.
//Figured out the error, look at the correction in comments below//Ans 2: Working on it
//Reverse a linked list without recursion.
class link
{
int data;
public link nextlink;
link(int d1)
{
data = d1;
}
}class List{
link head;
link revhead;
List(){
head = null;
}
boolean isEmpty(link head)
{
return head==null;
}
void insert(int d1)
{
link templink = new link(d1);
templink.nextlink = head;
head = templink;
}
void printlist(){
link head1 = head;
while(!isEmpty(head1))
{
System.out.print(head1.data + " ");
head1 = head1.nextlink;
}
System.out.println();
}
void reverse()
{
link previous=null,temp=null;
while(isEmpty(head))
{
temp = head.nextlink;
head.nextlink = previous;
previous = head;
head = temp;
}
}}
public class LinkedList {
public static void main(String[] args) {
List list1 = new List();
list1.insert(10);
list1.insert(20);
list1.insert(30);
list1.insert(40);
list1.insert(50);
list1.printlist();
list1.reverse();
list1.printlist();
}}
2.) There is a paragraph of infinite length. WAP to find the length of words having maximum length of prefix.
Find out the complexity of the algorithm.
Amazon telliphonic 17 May, 2012
1.) There is a sequence where aphabets are written like this..
a,b,c,d,.......,x,y,z,aa,ab,ac........,az,ba,bb,bc,bd......bz,ca,cb.........cz........,aaa,aab,aac.....aaz,............zzz,aaaa...........zzzz..... and so on..
WAP to find out the string value at kth position.like if k= 28 the string on 28 will be "ab".
What type of responsibilities are you seeking in a new role? What is your career objective? Why PayPal/Ebay ?

