Welcome Message

Hi, welcome to my website. This is a place where you can get all the questions, puzzles, algorithms asked in interviews and their solutions. Feel free to contact me if you have any queries / suggestions and please leave your valuable comments.. Thanks for visiting -Pragya.

January 28, 2018

Binary Search

package com.mylearnings;

public class BinarySearch {

public static void main(String[] args) {
int input[] = {5,7,6,8,65,87,12,3,343,44,767,78};
int sortedInput[] = {5,6,12,15,18,25,45,65,70,75,78,80,82,83,85,88,90,98,100,105,107};
BinarySearch search  = new BinarySearch();
int index = search.binarySearch(sortedInput, 0, sortedInput.length, 65);
System.out.println(index);
}

public int binarySearch(int[] input, int startIndex, int endIndex, int search) {
if(startIndex <= endIndex) {

int mid= startIndex + (endIndex - startIndex)/2;
int midVal = input[mid];
if(midVal == search) {
//System.out.println("Value found at index : "+mid);
return mid;
}else if(search < midVal) {
return binarySearch(input, startIndex , mid-1, search);
}else {
return binarySearch(input, mid+1, endIndex, search);
}
}

return -1;
}

}

January 23, 2018

Stack of Integers

package com.mylearnings;

public class IntStack {

int size;
int[] stack;
int top;

IntStack() {
size = 50;
top = -1;
stack = new int[50];
}

IntStack(int size) {
this.size = size;
top = -1;
stack = new int[size];
}

public boolean push(int value) {

if (!isFull()) {
stack[++top] = value;
return true;
}
return false;
}

public int pop() {
return stack[top--];
}

public boolean isFull() {
return top == size - 1;
}

public boolean isEmpty() {
return top == -1;
}

}

----------------------------------------------------------------

Main class

package com.mylearnings;

public class IntStackMain {

public static void main(String[] args) {
IntStack stack = new IntStack(10);
stack.push(1);
stack.push(2);
stack.push(3);
stack.push(4);
System.out.println(stack.pop());
System.out.println(stack.pop());
System.out.println(stack.pop());
System.out.println(stack.pop());

}

}

June 20, 2012

InvalidMonitorStateException

This exception is thrown when we call wait(), notify() or notifyAll() methods from any object when we are not having lock on that object.

This exception is a sub-class of RuntimeException. So we donot need to handle this.
Also this is the reason why the signatures of  wait(), notify() or notifyAll() do not have this exception declared .

Thread.run() and Thread.start()

Thread.start() essentially calls run() method only.
If we call Thread.run() directly, it will be executed in the same thread and a new thread would not be created.
So the purpose of multithreading is not fulfilled.

May 24, 2012

Defining priority / order of advice in Spring AOP

We can use @Order annotation to define the Order of advice

February 22, 2012

Webservices - Basics

1. Service over web
2. Language independent
3. Communicate mostly over HTTP, but can communicate over other transfer protocols as well
4. Two types : SOAP(Simple Object Access Protocol) based and REST(representational State Transfer) style
5. The client of webservices is generally an application without any user interface.
6. In a SOAP based webservice, a client generally sends SOAP document as request and gets SOAP based document as response. In a REST style WS, a client might send a standard http request and get an XML document as response.
7. Java 6 supports JAX-WS which supports both REST and SOAP webservices.

December 29, 2011

Strategy Pattern

Key points :

1. Also known as Policy pattern
2. Collection of Algos (Behavuours)
3. Algo can be selected at runtime
4. Uses composition instead of inheritance

e.g. a class used for validation of incoming data may use strategy pattern in which the validation algo will be decided on the basis of data set

June 20, 2011

LimeSpot interview Question (Telephonic Interview)

Currently there are three projects in LimeWire :
1. LimeWire
2. Lime Domain : Hosts domain for users
3. LIme Exchange

Q1: What in an outer join and what is an Inner join?
A: Inner Join returns a row when there is at-least one match in one match in both the tables. e.g.
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
FROM Persons
INNER JOIN Orders
ON Persons.P_Id=Orders.P_Id
ORDER BY Persons.LastName

http://www.w3schools.com/sql/sql_join_inner.asp

Outer JOin :
Returns a row even if there is no match.
An outer join does not require each record in the two joined tables to have a matching record. The joined table retains each record—even if no other matching record exists. Outer joins subdivide further into left outer joins, right outer joins, and full outer joins, depending on which table(s) one retains the rows from (left, right, or both).

Q2. What is Normalisation and what is BCNF?
A: Boyce Codd Normal Form