lks
BAN USER- 0of 0 votes
AnswersConsider there is a streaming service, which outputs Log object to your service. The Log object has fields like {timeStamp, userId, hashtag(used in the tweet), @userAddressUsedInTweet} etc. Imagine this streaming service has very high QPS. Design your service in such a way that it can output top K userId's within a configurable time window(example: last 1 hour, last 24 hour etc). This service should be extendable to get any top K category (Example: TopK userId's, TopK hashtags etc). What would you use to design such a service. Top K is defined by its frequency, example: 1,2,3,4,1,2,1,2,1,1,5 are the userIDs then the top 2 users are userId 1 and 2.
- lks in United States
@EdgeCase:
1. Take into consideration how to store data in that window to get the topK user's.
2. The service should be highly available and should return the results quickly
3. Design and implement this service| Report Duplicate | Flag | PURGE
Google Software Engineer - 0of 0 votes
AnswersDesign classes to represent the following problem and solve the questions 1,2,3
- lks in United States
A user might have some outstanding auto loan amount and you have 3 types of offers: personal loan, credit card and auto loan offers. You need to provide the user
with the following details:
1. Send user all the offers to the user
2. Send user all eligible offers (where minCreditScore < userCreditScore < maxCreditScore)
3. Send user all offers which satisfied 2) and where the (userOutStandingLoanAmount < maxOfferedAutoLoanAmount)
personal-loan = [{
"personal-loan": {
"id": 1,
"provider": "Avant",
"term": 36,
"minimumCreditScore": 300,
"maximumCreditScore": 700,
"maximumAmount": 10000
}
}, {
"personal-loan": {
"id": 2,
"provider": "Prosper",
"term": 24,
"minimumCreditScore": 600,
"maximumCreditScore": 700,
"maximumAmount": 5000
}
}]
credit-card=[{
"credit-card": {
"id": 2,
"provider": "CapitalOne",
"minimumCreditScore": 600,
"maximumCreditScore": 700
}
}, {
"credit-card": {
"id": 3,
"provider": "Chase",
"minimumCreditScore": 300,
"maximumCreditScore": 900
}
}]
autoloan = [{
"auto-loan": {
"id": 1,
"provider": "CapitalOne",
"term": 36,
"minimumCreditScore": 300,
"maximumCreditScore": 700,
"maximumAmount": 10000
}
}, {
"auto-loan": {
"id": 2,
"provider": "Blue Harbor",
"term": 24,
"minimumCreditScore": 600,
"maximumCreditScore": 700,
"maximumAmount": 5000
}
}]| Report Duplicate | Flag | PURGE
Uber Software Engineer - 0of 4 votes
AnswersTake an example of the traditional Iterator interface which has the following methods
- lks in United States
Interface Iterator<E>{
public boolean hasNext() {}
public E next() {}
public E remove() {}
}
You are given a list of iterators. You have to design a InterleaveIterator class which implements this
interface and implement the methods:
hasNext() and next()
such that these 2 methods returns interleaved values for the list of iterators:
Implement:
class InterleaveIterator<E> implements Iterator<E>{
@override
public boolean hasNext() {}
@override
public E next() {}
}
Example:
ArrayList<Integer> i1 = [1,2,3,4,5].iterator()
List<Node> i2 = [n1,n2].iterator()
Collection<E> i3 = [e1,e2,e3].iterator()
next() method of InterleaveIterator, should return in this sequence [1,n1,e1,2,n2,e3,3,e3,4,5]
Make this InterleaveIterator class generic and make sure that the class can accept a list of iterators
and interleave them| Report Duplicate | Flag | PURGE
Google SDE-2 Coding - 0of 0 votes
AnswersFind the longest common substring between 2 string in O(n) complexity
- lks in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersSecond Question is to Encode a String
- lks in United States
aaaabbccdd -> a4b2c2d2
In minimun space and time complexity| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 0of 0 votes
AnswersImplement stack with findMiddle and deleteMiddle() in constant time.
- lks in United States
Can you please explain and write code for it| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersGiven a binary search tree whose nodes are integers, find the frequency of occurrence of each digit in the tree.tr
- lks in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Trees and Graphs - 0of 0 votes
AnswersHow would you represent a graph with million nodes ?
- lks in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 1of 1 vote
AnswersThere are two questions that I want to ask.
- lks in United States
Q1) divide two numbers without “/”
Q2) judge if there are two numbers in an array add to a given number
For both the questions please consider minimum space and time complexity| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersGiven a collection of 3-set sequences, where a 3-set sequence is defined as a list of 3 different pages (for example: mouse-keyboard-printer is a 3-set sequence, while printer-mouse-keyboard is another) accessed sequentially on amazon.com, find the most common 3-set sequence with minimum space and time complexity
- lks in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 1of 1 vote
AnswersWrite a function to remove all redundant characters in a given string with minimum space and time complexity
- lks in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures
There shouldn't be any duplicates in the array.
The below java code would work fine
public static int findElement(int[] a, int low, int high, int x)
{
while(low<=high)
{
int mid=(low+high)/2;
if(a[mid]==x)
return mid;
else if(a[mid]<=a[high]){
if(x>a[mid]&&x<a[high])
low=mid+1;
else
high=mid-1;
}
else
{
if(x<a[mid]&&x>a[low])
high=mid-1;
else
low=mid+1;
}
}
return -1;
}
There shouldn't be any duplicates in the array.
The below java code would work fine
public static int findElement(int[] a, int low, int high, int x)
{
while(low<=high)
{
int mid=(low+high)/2;
if(a[mid]==x)
return mid;
else if(a[mid]<=a[high]){
if(x>a[mid]&&x<a[high])
low=mid+1;
else
high=mid-1;
}
else
{
if(x<a[mid]&&x>a[low])
high=mid-1;
else
low=mid+1;
}
}
return -1;
}
So this is what ur complete code shld look :
public ListNode addLinkedListNodes(ListNode a, ListNode b) {
ListNode resultP = null;
ListNode result = resultP;
int carry = 0;
while (a != null || b!= null) {
if (resultP == null) {
resultP = new ListNode();
} else {
resultP.next = new ListNode();
resultP = resultP.next();
}
if (a == null) {
result.value = (b.value + carry) %10;
carry = (b.value + carry) / 10;
b = b.next;
} else if (b == null) {
result.value = (a.value + carry) % 10;
carry = (a.value + carry) / 10;
a = a.next;
} else {
result.value = (a.value + b.value + carry) % 10;
carry = (a.value + b.value + carry) / 10;
a = a.next;
b = b.next;
}
}
if (carry > 0) {
resultP.next = new ListNode();
resultP.next.value = carry;
result=resultP;
}
return result;
}
Correct me If I am worng
There is a bug is in the while condition.
The while condition should be while(num>=divisor)
Because for divisors which divide the number with a zero remainder, the quotient returned is 1 less.
After correcting the while condition to while(num>=divisor), the program would return the correct quotient for all possible sequence of number and divisor
Can someone please implement this in Java ?
- lks December 09, 2017