CareerCupUser1
BAN USER- 0of 0 votes
AnswerWrite a program for skyyscrapper?
- CareerCupUser1 in United States
http://www.conceptispuzzles.com/index.aspx?uri=puzzle/skyscrapers/techniques| Report Duplicate | Flag | PURGE
Google SDE-3 Algorithm - 0of 0 votes
AnswersYou are given an scenario where there is an Worker object. Each Worker object has one mandatory field unique id workerId and their are few other non unique and not mandatory Ids : DeptId and UnitID.
- CareerCupUser1 in United States
Design an cache for your Worker objects considering the fact that most of the queries on your cache will be on unitId. If the there is an query for an Worker which is not available in your cache then that data will be fetched from the server.
Design an cache such that there will be minimum number of server calls. Imagine there are 100;s of such non unique ids non mandatory Ids in the Worker object and you have to design the cache so that your client can query on any given id with minimum calls to server.
Your Worker object looks like this:
Worker1=> workerid=1, deptId=>765, unitId=>123 Name=“” Surname=“” Data=“”
Worker2=> workerid=2 , deptId=>765 Name=“” Surname=“” Data=“”
Worker3=> workerid=3, unitid=>123 Name=“” Surname=“” Data=“”
so when your client queries using unitId getWorkersbyUnitId(123) it should return Worker1 and Worker3.
If query is on deptId 765 then it should return Worker1 and Worker2
You can assume there is never an query on individual workerId.
other information given while discussion is you can query the server using any id and all the worker objects of that id will be fetched by that single call: Example there are 10 workers associated with untId: 99 then server call to getserverUnitIdWorkers(99)-> will output list of 10 workers. Each unitId or any other non mandatory id has approximate 8 to 10 workers associated with it. And there are millions of such unitIds.| Report Duplicate | Flag | PURGE
Google Senior Software Development Engineer Cache - 0of 0 votes
AnswersProcess name is VistaarAddUser.sh, but pgrep command doesnt prints the fullname while listing[if path of process is too long],
- CareerCupUser1 in India
example
pgrep -lfu $UID|grep 17882
results in,
17882 bash +x /data/rdg2/Vistaar/Common/ToolKit/../../Analytics/ToolKit/bin/VistaarAd
how do u print the full name with path of process using pgrep itself| Report Duplicate | Flag | PURGE
Unix
public static int getMax(int[] arr){
int maxsum=0;
int sum=0;
for(int i=0;i<arr.length;i++){
sum+=arr[i];
if(maxsum < sum)
maxsum=sum;
else if(sum<0)
sum=0;
}
return maxsum;
}
Note:It will not work if array has all negative values.
- CareerCupUser1 May 29, 2012we can solve this problem with fast and slow pointer concept
public boolean isPalindrome(Node head)
{
Node slwptr=head;
Node fstptr=head;
Stack<int> s1=new Stack<int>();
while(fstptr!=null && fstptr.next!=null)
{
s1.push(slwptr.data);
slwptr=slwptr.next;
fstptr=fstptr.next.next;
}
if(fstptr!=null)
slwptr=slwptr.next;
while(slwptr!=null)
{
if(slwptr!=s1.pop())
return false;
}
return true;
}
we can solve this problem with fast and slow pointer concept
public boolean isPalindrome(Node head)
{
Node slwptr=head;
Node fstptr=head;
Stack<int> s1=new Stack<int>();
while(fstptr!=null && fstptr.next!=null)
{
s1.push(slwptr.data);
slwptr=slwptr.next;
fstptr=fstptr.next.next;
}
if(fstptr!=null)
slwptr=slwptr.next;
while(slwptr!=null)
{
if(slwptr!=s1.pop())
return false;
}
return true;
}
Regex for any email id, that can ends with com edu or anything:
^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+
(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$
^ #start of the line
[_A-Za-z0-9-]+ # must start with string in the bracket [ ], must contains one or more (+)
( # start of group #1
\\.[_A-Za-z0-9-]+ # follow by a dot "." and string in the bracket [ ], must contains one or more (+)
)* # end of group #1, this group is optional (*)
@ # must contains a "@" symbol
[A-Za-z0-9]+ # follow by string in the bracket [ ], must contains one or more (+)
( # start of group #2 - first level TLD checking
\\.[A-Za-z0-9]+ # follow by a dot "." and string in the bracket [ ], must contains one or more (+)
)* # end of group #2, this group is optional (*)
( # start of group #3 - second level TLD checking
\\.[A-Za-z]{2,} # follow by a dot "." and string in the bracket [ ], with minimum length of 2
) # end of group #3
$ #end of the line
can you please write code snippet
- CareerCupUser1 January 11, 2012we can use Hash for storing the character as key and value as number of occurrences and keep on incrementing for note and decrementing for magzine
- CareerCupUser1 January 06, 2012
there is no issue of space here. we can store as many objects as we want just to keep the minimal server calls.
- CareerCupUser1 April 16, 2016Your first map is storing unitId=>starting address of worker object + number of other Workers of same unit Id. What is the use of storing just the number of Worker Objects? How will you get the worker objects of those workers?
Also keeping separate cache for each Id => worker object does not seems efficient as it already said there could be 100 of such different fields by which user wants to query so in that case would you create 100 maps?