Subhash
BAN USER
Iam a software Engineer in an American MNC
- 0of 0 votes
AnswersI have a following table with coloumn structure as shown below:
- Subhash
FROM TO PRICE STARTDATE ENDDATE
Mum Ban 2000 1stjan07 31stjan07
Mum Goa 3000 1stjan07 31stjan07
Goa Del 5000 1stjan07 31stjan07
.. .. .. ... ..
Mum Ban 1000 1stFeb07 28thjan07
Mum Goa 3000 1stFeb07 28thjan07
Goa Del 5000 1stFeb07 28thjan07
Like this it will be for all other months
So write a query in SQL which will show the output as shown below:
Date TO FROM PRICE
1stjan07 Mum Bang 2000
1stjan07 Mum Goa 3000
1stjan07 Goa Del 5000
2ndjan07 Mum Bang 2000
2ndjan07 Mum Goa 3000
2ndjan07 Goa Del 5000
and like this
we have to arrange it like date wise?| Report Duplicate | Flag | PURGE
Kingfisher Analyst Database - 1of 0 votes
Answersi have number of 10 digits lets say
- Subhash
ABCDEFGHIJ
A represents the number of 0's the above number has,B contains the number of 1's the above number has and so on...
Can you find out that number......| Report Duplicate | Flag | PURGE
Oracle Software Engineer / Developer Brain Teasers - 0of 0 votes
Answersint function findValue(int[]arr,int val,intlowIdx,int highIdx)
- Subhash
{
if(lowIdx>=higIdx)
return -1;
int midIdx:=Math.floor((lowIdx+higIdx)/2);
if(value>arr[midIdx])
return findValue(arr,value,midIdx+1,highIdx)
else if (value<arr[midIdx])
return findValue(arr,value,lowIdx,midIdx-1)
else
return midIdx;
}
And
int arr[]={1,2,3,5,8,13,21,34,55,89};
int n=arr.length;
What is the worse case order of execution if a call is made to
findValue(arr,<input from user>,0,arr.length -1)
a: log(n) log is of base 2
b: n**2
c: n*2
d: n| Report Duplicate | Flag | PURGE
Goldman Sachs Software Engineer / Developer Java
"
" you can figure out that for any given door, say door #42, you will visit it for every divisor it has. so 42 has 1 & 42, 2 & 21, 3 & 14, 6 & 7. so on pass 1 i will open the door, pass 2 i will close it, pass 3 open, pass 6 close, pass 7 open, pass 14 close, pass 21 open, pass 42 close. for every pair of divisors the door will just end up back in its initial state. so you might think that every door will end up closed? well what about door #9. 9 has the divisors 1 & 9, 3 & 3. but 3 is repeated because 9 is a perfect square, so you will only visit door #9, on pass 1, 3, and 9... leaving it open at the end. only perfect square doors will be open at the end. "
"
- Subhash April 02, 2007
import java.util.ArrayList;
- Subhash July 16, 2007/*
This program makes a random tree containing 1023 random
real numbers. It then computes the height of the tree and the
average depth of the leaves of the tree. Hopefully, the average
depth will tend to be close to 9, which is what it would be
if the tree were perfectly balanced. The height of the tree,
which is the same as the maximum depth of any leaf, can be
significantly larger.
*/
public class Example
{
static TreeNode root; // Pointer to the binary sort tree.
static class TreeNode
{
// An object of type TreeNode represents one node
// in a binary tree of real numbers.
double item; // The data in this node.
TreeNode left; // Pointer to left subtree.
TreeNode right; // Pointer to right subtree.
TreeNode(double x)
{
// Constructor. Make a node containing x.
item = x;
}
} // end class TreeNode
static void treeInsert(double x)
{
// Add x to the binary sort tree to which the
// global variable "root" refers.
if ( root == null )
{
// The tree is empty. Set root to point to a new node
// containing the new item.
root = new TreeNode( x );
return;
}
TreeNode runner; // Runs down the tree to find a place for newItem.
runner = root; // Start at the root.
while (true)
{
if ( x < runner.item )
{
// Since the new item is less than the item in runner,
// it belongs in the left subtree of runner. If there
// is an open space at runner.left, add a node there.
// Otherwise, advance runner down one level to the left.
if ( runner.left == null )
{
runner.left = new TreeNode( x );
return; // New item has been added to the tree.
}
else
runner = runner.left;
}
else
{
// Since the new item is greater than or equal to the
// item in runner, it belongs in the right subtree of
// runner. If there is an open space at runner.right,
// add a new node there. Otherwise, advance runner
// down one level to the right.
if ( runner.right == null )
{
runner.right = new TreeNode( x );
return; // New item has been added to the tree.
}
else
runner = runner.right;
}
} // end while
} // end treeInsert()
static int countLeaves(TreeNode node)
{
// Return the number of leaves in the tree to which node points.
if (node == null)
return 0;
else if (node.left == null && node.right == null)
return 1; // Node is a leaf.
else
return countLeaves(node.left) + countLeaves(node.right);
} // end countNodes()
static int sumOfLeafDepths( TreeNode node, int depth )
{
// When called as sumOfLeafDepths(root,0), this will compute the
// sum of the depths of all the leaves in the tree to which root
// points. When called recursively, the depth parameter gives
// the depth of the node, and the routine returns the sum of the
// depths of the leaves in the subtree to which node points.
// In each recursive call to this routine, depth goes up by one.
if ( node == null )
{
// Since the tree is empty and there are no leaves,
// the sum is zero.
return 0;
}
else if ( node.left == null && node.right == null)
{
// The node is a leaf, and there are no subtrees of node, so
// the sum of the leaf depth is just the depths of this node.
return depth;
}
else
{
// The node is not a leaf. Return the sum of the
// the depths of the leaves in the subtrees.
return sumOfLeafDepths(node.left, depth + 1)
+ sumOfLeafDepths(node.right, depth + 1);
}
} // end sumOfLeafDepth()
static int maximumLeafDepth( TreeNode node, int depth )
{
// When called as maximumLeafDepth(root,0), this will compute the
// max of the depths of all the leaves in the tree to which root
// points. When called recursively, the depth parameter gives
// the depth of the node, and the routine returns the max of the
// depths of the leaves in the subtree to which node points.
// In each recursive call to this routine, depth goes up by one.
if ( node == null )
{
// The tree is empty. Return 0.
return 0;
}
else if ( node.left == null && node.right == null)
{
// The node is a leaf, so the maximum depth in this
// subtree is the depth of this node (the only leaf
// that it contains).
return depth;
}
else
{
// Get the maximum depths for the two subtrees of this
// node. Return the larger of the two values, which
// represents the maximum in the tree overall.
int leftMax = maximumLeafDepth(node.left, depth + 1);
int rightMax = maximumLeafDepth(node.right, depth + 1);
if (leftMax > rightMax)
return leftMax;
else
return rightMax;
}
} // end sumOfLeafDepth()
public static void main(String[] args)
{
// The main routine makes the random tree and prints
// the statistics.
root = null; // Start with an empty tree. Root is a global
// variable, defined at the top of the class.
// Insert 1023 random items.
for (int i = 0; i < 1023; i++)
treeInsert(Math.random());
// Get the statistics.
int leafCount = countLeaves(root);
int depthSum = sumOfLeafDepths(root,0);
int depthMax = maximumLeafDepth(root,0);
double averageDepth = ((double)depthSum) / leafCount;
// Display the results.
System.out.println("Number of leaves: " + leafCount);
System.out.println("Average depth of leaves: " + averageDepth);
System.out.println("Maximum depth of leaves: " + depthMax);
} // end main()
}