turukmakto1990
BAN USER
I think we should have a lock time based on amount of quantity available and the customer should be notified when he adds the item to cart that the item is only guaranteed for x amount of time based on the lock time we calculated. The item should be shown as unavailable for that period of time to other customers.
Other approach is to divide the type of items into two categories, one which can be backordered if over-ordered and others which cannot be. For the 1st option, we should allow customers to order the item as long as they started the checkout process before anyone else purchased it and then provide them the backordered status. For the other type, we just need to show unavailable message if payment fails due to unavailability.
1) Use distributed caching like memcached
2) Have a central computer which will act as primary server for processing final results.
Add multiple secondary computer as backups incase primary goes down.
3) The central computer cluster updates a threshold for count of most visited urls.
We can either put the threshold in memcached or distribute it using an observer pattern where all
registered computers get the updated threshold.
4) Each computer calculates up the 10 max urls by visited count which are more than the
threshold and update them in memcached. This can be either scheduled or triggered when they are notified
in the observer pattern.
5) The central computer will iterate over all the data cached in memcached and calculates the top ten.
List<Integer> list = new ArrayList();
for(int num: arr){
if(list.contains(num){
list.remove(num);
}
else{
list.add(num);
}
}
System.out.println(list);
java code using DP, also gives the moves
public class PotOfGold {
static int[] arr;
static int playerInd = 0;
public static void main(String args[]){
arr = new int[]{3, 4, 5, 7, 12, 13, 6, 1};
int len = arr.length;
Strategy strategy = maxGold(0, len-1);
System.out.println(strategy.sum);
System.out.println(strategy.moves);
}
static Map<String, Strategy> map = new HashMap();
private static Strategy maxGold(int start, int end) {
//System.out.println(start+" "+end);
Strategy strategy;
if(start > end){
strategy = new Strategy();
strategy.sum = 0;
strategy.moves = "";
return strategy;
}
String key = start+"-"+end;
if(map.containsKey(key)){
return map.get(key);
}
Strategy strategy1 = new Strategy(min(maxGold(start+2, end), maxGold(start+1, end-1)), arr[start]);
Strategy strategy2 = new Strategy(min(maxGold(start+1, end-1), maxGold(start, end-2)), arr[end]);;
strategy = max(strategy1, strategy2);
map.put(key, strategy);
return strategy;
}
public static Strategy min(Strategy strategy1, Strategy strategy2){
if(strategy1.compareTo(strategy2) < 0){
return strategy1;
}
return strategy2;
}
public static Strategy max(Strategy strategy1, Strategy strategy2){
if(strategy1.compareTo(strategy2) >= 0){
return strategy1;
}
return strategy2;
}
}
class Strategy implements Comparable{
int sum;
String moves;
Strategy(){
}
Strategy(Strategy strategy1, int val){
sum = val+strategy1.sum;
moves = val+" "+strategy1.moves;
}
@Override
public int compareTo(Object o) {
Strategy strategy1 = (Strategy)o;
return this.sum - strategy1.sum;
}
java code. Find approx sqrt of k and then add the element at that row and col index and all elements in right top and left bottom part of matrix to priority queue and poll it until you get the kth max element.
{{
int len = matrix.length;
int pos = (int)Math.pow(k, 0.5)-1;
PriorityQueue<Integer> pq = new PriorityQueue();
pq.add(matrix[pos][pos]);
for(int i = 0; i < pos; i++){
for(int j = pos+1; j < len; j++){
pq.add(matrix[i][j]);
pq.add(matrix[j][i]);
}
}
int currentEl = -1;
int piv = (int)Math.pow(pos+1, 2);
while(piv <= k){
currentEl = pq.poll();
piv++;
}
System.out.println(currentEl);
}}
char[] chArr = str.toCharArray();
int mid = chArr.length/2;
boolean isPalindrome = true;
for(int i = mid; i >= 0; --i){
isPalindrome = true;
for(int j = 1; j < chArr.length-i && j < i; j++){
if(chArr[i-j] != chArr[i+j]){
isPalindrome = false;
break;
}
}
if(isPalindrome){
StringBuffer strBuff = new StringBuffer();
for(int k = chArr.length-1; k > 2*i; --k){
strBuff.append(chArr[k]);
}
strBuff.append(str);
System.out.println(strBuff.toString());
break;
}
isPalindrome = true;
}
What does removing in-order mean ? Does it mean all characters before current character to be removed in the string should be removed as well ?
- turukmakto1990 December 14, 20161) What kind of alarms will be raised? (emails, pageouts) -
We can have an alarming interface on the server side and each type of alarm (email, pageout) will implement it and using a factory class we can get appropriate instance of alarm system.
2) Does data need to be logged for future reference and how long?
3) How often patterns change ?
If they change frequently, we can implement observer pattern where the logging process running on each app server will register itself as observer. Every new pattern added on the logging system will be distributed to all app servers.
4) For notifying logging system about the events, we can either use simple messaging service.
Logging System
1) Pattern database and Pattern publisher.
2) Event Collector (messaging service)
3) Alarm Interface and implementing classes.
4) Event database
5) GUI to add new patterns and view event history.
App Server
1) Daemon process monitoring the patterns distributed by logging system.
Convert the object into a byte array and split the array into multiple arrays each equal to 1 MB (size - 1024*1024). Store each of the subarrays in the cache using their hashcode. Create a list which contains all such hashcodes of the subarrays and store it against the original key in the cache.
- turukmakto1990 December 14, 2016few questions to ask
1) How many users?
2) Will it have gui interface?
3) Authentication required?
4) Will it also access secured websites?
5) Will tool be used all over the world or by specific region?
If tool used over multiple regions, it will be wise to store the data from each region in seperate database which will ensure better scalability.
Seperate process to crawl different sites can also help with scalability.
Questions to ask - 1) Can the Id be sequential or random ? 2) Any input which needs to be used in generation of ID 3) Numeric or can contain other characters 4) Service Interface (GUI/API) 5) Number of requests per second
Assuming that sequential is allowed and no input required, One way to generate it will be
BigInteger SMALLEST_64_BIT_NUM = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE);
Long seq = <current sequence value from DB sequence which is reset every day>;
Long currDate = 8 digit representation in format MMDDYYYY
return SMALLEST_64_BIT_NUM.add(currDate ).add(seq);
Have a one to one meeting with him. Check with him if he is facing any roadblocks in completing his tasks. If required arrange a training course for him or assign a mentor to work with him. Once training is over, give him ownership of some tasks and see if there is any improvement. If he expresses interest in some other area of work, help him in getting in touch with managers in that area and ensure a smooth transition for him and for the team.
- turukmakto1990 January 17, 2017