confused_coder
BAN USER- -6of 8 votes
AnswersBlacklist all the nodes in a B-tree, when viewed from all 4 directions.
- confused_coder in United States| Report Duplicate | Flag | PURGE
Google
- 0 Answers Black-listing nodes in a Btree
Does anyone know how to do this?
- confused_coder March 26, 2013| Flag | PURGE
Way I:
assuming each server takes the same time to sync, you could divide the cluster into groups of 10 and the central time server can sync them in groups.
pros:
-easy to maintain grouping
-grouping map can be stored on central time server
cons:
-if central server fails, may need to do resyncing
-if one or more of the servers in a group fail to sync or take too long then the other servers will be kept waiting
Way II:
let the central server have a list of sync'd, syncing and to be sync'd servers
the central server can start with a random 10 servers and change their state from to be
sync'd to syncing and update the lists.
When a server finished syncing, its state is changed to sync'd and added to the sync'd list. Next, a new server can be sync'd if space is available.
pros:
-servers don't constantly wait unnecessarily
- a priority can be assigned to certain servers if dependencies exist
- can retry on sync errors
cons:
-if central server fails, need to redo syncing. To combat this each server can store their state, so when the central server comes back online, it can poll the cluster to see what needs to be done and recreate its lists
You'd need a mapping of keywords to songs
Keywords can include popular phrases/lyrics from the song, artist name, album name, genre, etc
For example
bad -> bad blood, bad romance, taylor, swift, taylor swift, lady gaga, gaga, etc
something -> something about you, something in the way you move etc
You would also need a mapping of songs to key words
For example
bad blood -> taylor swift, 1989
something in the way you move -> ellie goulding, delirium etc
You could use these two hash tables to get a list of relevant results for a search keyword/phrase
You could also cache a list of recent search queries and results (for auto fill and fast data service), if needed
Categorized search can also be used, eg search by artist, song, album; this could use category specific tables for quick look up
What is the carousal system on Amazon? You mean the marquee in a div that says you may like these other products??
For each user, have a list of recently bought products
For each product store a list of products bought along with it (use a heap if you want for this)
Combine these two lists together, plus a few more products based on the category of the item and items recently looked at by the user etc
Use the observer pattern here.
Have a list of pages (friends, trending etc) that a user follows
In order of priority list the most recent posts according to time stamps
Refresh the feed every 2 mins or so
You could use a supervised algorithm for this.
Provide the number of people required on a given day at a given time for a time-frame (say past one month). A good algorithm can predict the number required now.
Or in a crude manner, base the required number off last year's data, allowing for a buffer, such as lesser employees etc
@asen
We don't really want a hard lock in this situation. I'm assuming a discrepancy of say 10 counts is acceptable.
You can always let your current browser video view count increment and send the count update request to the server. The server can queue the requests and update the count when processing the requests. With this scheme, the difference in view counts can be greater than one when you refresh the video.
Assuming the system to be designed is strictly for monitoring purposes, we can make use of the Observer design pattern here. This way the system can be portable to web applications as well as devices.
When the hotel booking system receives a confirmation, a `bookingNotifier` can send out a message with the necessary details (for eg, hotel name, suite, number of people, location, dates etc). Similarly, a `cancellationNotifier` and a `bookingUpdateNotifier` can exist as well. These three notifier types can send messages to a `notificationPublisher` class which processes the information received and looks at the users and/or applications to be notified, and queues a message in those user's message queue.
A `notificationSubscriber` class regularly polls the user's message queues for "immediate automatic push type updates" and looks at the subscription preferences and sends up the message in that manner. For non-automatic push updates, the messages can be displayed on first login for a day, or daily login (this is something that should be discusses with the interviewer; each option has it's own set of pros and cons).
This notification system can be tightly coupled with the booking/reservation system
you would need to have a good hashing algorithm to hash out keys for all the values
- confused_coder August 19, 2016Keep a running sum, with two runners `start` and `end` that check the subsequences
O(n) and constant space
Node removeRedundantNodes(Node head)
{
if (head == null || head.next == null)
return head;
Node start = head;
Node end = head; // or Node end = start;
int sum = 0;
while (start != null || end != null)
{
sum += end.value;
if (sum == 0)
{
// found a redundant sub-sequence!
start = end.next;
end = start;
}
else
{
end = end.next;
}
}
return start;
}
int findMinCost(int[][] inputMatrix)
{
if (inputMatrix == null || inputMatrix.length == 0)
return -1;
int[][] minCost = new int[inputMatrix.length][inputMatrix[0].length];
minCost[0][0] = inputMatrix[0][0];
for (int i = 1; i < inputMatrix.length(); i++)
{
minCost[0][i] = minCost[0][i-1] + inputMatrix[0][i];
}
for (int i = 1; i < inputMatrix[0].length(); i++)
{
minCost[i][o] = minCost[i-1][0] + inputMatrix[i][0];
}
for (int i = 1; i < inputMatrix.length(); i++)
{
for (int j = 1; j < inputMatrix[0].length(); j++)
{
minCost[i][j] = Math.min(minCost[i-1][j-1], Math.min(minCost[i-1][j], minCost[i][j-1])) + inputMatrix[i][j];
}
}
return minCost[inputMatrix.length - 1][inputMatrix[0].length -1];
}
if the points are all the same or lie in a straight line, then it is not possible
To check if the three points can form a triangle, check the slopes of any two of the edges
like ((y2-y1)/(x2-x1))
ie if the slopes are equal then the points are on a line and cannot be part of a triangle.
To find outer 'normal' circle area:
1. find the centroid of the triangle (ie ((N1+N2+N3)/3, (M1+M2+M3)/3)
2. find the distance between the centroid of the triangle and any of its vertices (ie sqrt((x2-x2)^2 + (y2-y1)^2). This is the radius of the outer 'normal' circle
3. Calculate the area of the normal circle and store it in a variable, say double normalArea
To find inner 'strange circle' area:
1. find midpoint of any one of the triangle edges (ie (x1+x2)/2, (y1+y2)/2)
2. Measure the distance between this midpoint and the centroid of the triangle. This is the radius of
the inner 'strange' circle
3. Calculate its area (pi*r^2)
To find ring area: subtract the inner area from the outer area and return.
if the points are all the same or lie in a straight line, then it is not possible
To check if the three points can form a triangle, check the slopes of any two of the edges
like ((y2-y1)/(x2-x1))
ie if the slopes are equal then the points are on a line and cannot be part of a triangle.
To find outer 'normal' circle area:
1. find the centroid of the triangle (ie ((N1+N2+N3)/3, (M1+M2+M3)/3)
2. find the distance between the centroid of the triangle and any of its vertices (ie sqrt((x2-x2)^2 + (y2-y1)^2). This is the radius of the outer 'normal' circle
3. Calculate the area of the normal circle and store it in a variable, say double normalArea
To find inner 'strange circle' area:
1. find midpoint of any one of the triangle edges (ie (x1+x2)/2, (y1+y2)/2)
2. Measure the distance between this midpoint and the centroid of the triangle. This is the radius of
the inner 'strange' circle
3. Calculate its area (pi*r^2)
To find ring area: subtract the inner area from the outer area and return.
Assuming you mean 'any number of elements could be removed excluding the first and last elements'
boolean canBeSplitEqually(int[] array)
{
int start = 0;
int end = array.length() - 1;
int sumLeft = 0;
int sumRight = 0;
while (start < end)
{
sumLeft += array[start];
sumRight += array[end];
if (sumLeft == sumRight) // note lengths will automatically be equal
{
return true;
}
start++;
end--;
}
return false;
}
Instead of using two pointers, start and end which will modify the order, use start and middle so the order is preserved
int[] preservedSort(int[] array)
{
if (array == null || array.length() == 0)
return array;
int start = array[0];
int middle = array.length() / 2 ;
while(start < array.length() && middle < array.length())
{
if (array[start] > array[middle])
{
swap(array[start], array[middle]);
start++; middle++;
}
if (array[start] == 0) start++;
if (array[middle] == 1) middle++;
}
return array;
}
use a balanced binary search tree, similar to geeksforgeeks.org/count-smaller-elements-on-right-side
- confused_coder July 25, 2016is there nay more info on this problem?
1. you could 'ping' each entry in the array and return ones that succeeded (ie are valid)
2. you could specify a pattern to check each entry against (ie can't have characters other than '.', only numbers 0-9 etc)
1. you could store the incoming integers in a heap and look for two numbers that sum to 10
2. read each incoming number and see if it's compliment (against 10 exists in a hash table)
Use a stack.
// Note: does not compile! assumes negative numbers are after positive numbers in list
Node removeCancellableNodes(Node listHead)
{
if (listHead == null) return null; // or listHead
Stack<Node> stack = new Stack<Node>();
Node node = listHead;
while(node != null)
{
if (node.value < 0)
{
int sum = node.value;
while (!stack.isEmpty())
{
Node temp = stack.pop();
sum -= temp.value;
temp = null;
if (sum == 0)
{
node = stack.peek();
break;
}
}
}
else
{
stack.push(node);
}
node = node.next;
}
return listHead;
}
needs to cover non-continuous sequences..
- confused_coder March 18, 2013
What sort of questions did you ask, if you don't mind telling us
- confused_coder August 21, 2016