naveen kumar
BAN USERUsually websites like Flipkart will have 100s of servers. So what we can do is -
1. Every server we will maintain a map of MAP(Timestamp -> Number of concurrent connections) . This number of concurrent connections can be fetched by using Nagios which runs as a daemon on the server and counts the number of Apache processes in case the server is using apache.
2. Next we can have a worker server which will have a task of iterating through the timestamp and collecting the concurrent connections for that timestamp from all the servers , summing them up and storing it in some variable. Single vairable will give the max number of connections and at what timestamp that happened.
Hey bharajwad.... how much time is usually given for there questions by the interviewer??
- naveen kumar June 19, 2012int isPalindrome(struct node *head){
if(head->next == NULL){
return 1;
}
else
{
int isp;
struct node *left=head->next;
struct node *right = head->next;
isp = helperPalindrome(&left,right);
return isp;
}
}
int helperPalindrome(struct node **left, struct node *right){
int hisp;
if(right == NULL){
return 1;
}
else
{
hisp = helperPalindrome(left,right->next);
if(hisp == 1){
if((*left)->data == right->data){
*left=(*left)->next;
return 1;
}
else
return 0;
}
return 0;
}
}
done in o(1) space and o(1) time
ya sorry.... it should be node->left and node-> right
- naveen kumar May 25, 2012u can use || also....i just used it bcoz i had a macro for that:P
- naveen kumar May 25, 2012steps:
1. get the distance of the start node in the tree.
2. make a function printk(node , distance) which prints all the nodes at a level of k from the given node passed as a paramenter.
3. Run the printk(start node , k) with start node and k , it prints the nodes at level k down from the start node.
4. let k=4 for eg. and the level of start is 6 , so 6-4 = 2 is the level upto which we need to print the nodes. these will be the node k distance from the start node
5. done
struct maxSumAndNode{
int maxSum ;
struct node *maxNode ;
};
struct maxSumAndNode rootNodeWithLargestSumUpValue(struct node *node, int maximum, struct node *ret)
{
int tempSum ;
struct maxSumAndNode st1,st2;
if(node == NULL){
struct maxSumAndNode result;
result.maxSum = maximum ;
result.maxNode = ret;
return result;
}
else
{
if((tempSum = printSum(node) )> maximum)
{
maximum = tempSum ;
st1 = rootNodeWithLargestSumUpValue(node->left , maximum, node);
st2 = rootNodeWithLargestSumUpValue(node->right , maximum , node);
if(st1.maxSum > st2.maxSum)
{
return st1;
}
else
{
return st2;
}
}
else
{
maximum = maximum ;
st1= rootNodeWithLargestSumUpValue(node->left , maximum, ret);
st2 = rootNodeWithLargestSumUpValue(node->right , maximum , ret);
if(st1.maxSum > st2.maxSum)
{
return st1;
}
else
{
return st2;
}
}
}
}
struct maxSumAndNode{
int maxSum ;
struct node *maxNode ;
};
struct maxSumAndNode rootNodeWithLargestSumUpValue(struct node *node, int maximum, struct node *ret)
{
int tempSum ;
struct maxSumAndNode st1,st2;
if(node == NULL){
struct maxSumAndNode result;
result.maxSum = maximum ;
result.maxNode = ret;
return result;
}
else
{
if((tempSum = printSum(node) )> maximum)
{
maximum = tempSum ;
st1 = rootNodeWithLargestSumUpValue(node->left , maximum, node);
st2 = rootNodeWithLargestSumUpValue(node->right , maximum , node);
if(st1.maxSum > st2.maxSum)
{
return st1;
}
else
{
return st2;
}
}
else
{
maximum = maximum ;
st1= rootNodeWithLargestSumUpValue(node->left , maximum, ret);
st2 = rootNodeWithLargestSumUpValue(node->right , maximum , ret);
if(st1.maxSum > st2.maxSum)
{
return st1;
}
else
{
return st2;
}
}
}
}
int hasPathSum(struct node *node , int sum){
if(node == NULL)
return (0);
else {
sum-=(node->data);
if(node->left == NULL && node->right == NULL && sum == 0){
return (1);
}
else{
return(max(hasPathSum(node->left,sum),hasPathSum(node->left,sum)));
}
}
}
int hasPathSum(struct node *node , int sum){
if(node == NULL)
return (0);
else {
sum-=(node->data);
if(node->left == NULL && node->right == NULL && sum == 0){
return (1);
}
else{
return(max(hasPathSum(node->left,sum),hasPathSum(node->right,sum)));
}
}
}
int hasPathSum(struct node *node , int sum){
if(node == NULL)
return (0);
else {
sum-=(node->data);
if(node->left == NULL && node->right == NULL && sum == 0){
return (1);
}
else{
return(max(hasPathSum(node->left,sum),hasPathSum(node->left,sum)));
}
}
}
This is the DB way of doing it. Anyways we never index logs which are semi structured data to DB.
- naveen kumar October 18, 2014