Bevan
BAN USER- 0of 0 votes
AnswersWrite a code to find subset of numbers in array whose summation= given number? If this does not exist, print false
- Bevan in United States
I know the solution consisting of non-negative numbers.
Is there any smart solution when the array contains NEGATIVE numbers?? Thanks.| Report Duplicate | Flag | PURGE
Amazon - 0of 0 votes
AnswersHow to Reduce wait time in Elevator Design System?
- Bevan in United States
I am just curious to know if a greedy approach will work fine here?| Report Duplicate | Flag | PURGE
Amazon - 2of 2 votes
AnswersAssume I have a log file with list of people with their arrival and departure time at an event that happened in the past.
- Bevan in United States
My task is to find out the maximum number of people present at any time during the entire event? I am not given query time.
ai = Arrival time of person i
di = Departure time of person i
I have a list of pairs like (a1,d1), (a2,d2), (a3,d3).... (an,dn)... It's not in a database.
I apologize as I cannot edit my previous question. I think it had a incomplete description.
Please let me know if you guys still need clarification. Thanks| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 3of 5 votes
AnswersI was asked to design a meeting scheduler, just like in the Microsoft outlook calendar or the gmail calendar. I proposed that I will create an array of 48 for each day. Every 30 min representing the array entry.
- Bevan in United States for AWS
I have to make sure that the next appointment does not collide with a previous meeting.
My solution works fine but it wastes too much memory.
Can anyone please tell me how do I find a better solution to detect collision for meetings.
I don't know all the meetings at the beginning. They will be added randomly later.
Thanks,| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer System Design
- 1 Answer Samsung America
I have been offered an internship position by Samsung America as Android Software Developer. I accepted the offer and sent them signed application form. How long does it take for them to send me the offer letter. its been more than 2 weeks. Thanks.
- Bevan February 25, 2012| Flag | PURGE - 0 Answers I have been offered an interns...
I have been offered an internship position by Samsung America as Android Software Developer . I accepted the offer and sent them signed application form. How long does it take for them to send me the offer letter. its been more than 2 weeks. Thanks.
- Bevan February 24, 2012| Flag | PURGE
Yes. It is Breadth First Search.
Well, IF and only IF the problem has a size 7(or some small number), please feel free to go ahead with this 2D Structure.
But in practicality, this is never the case. You will be required to create adjacency list exactly as mentioned in the question.
Since you want a working code quickly, (there can multiple ways to implement this. I find this to be the simplest)
class Person
{
String name;
List<Person> friendsList;
}
some Global HashMap to get a quick handle of any Person..
now just scan the people.
look at their friend list. Use the Hashmap created above to get a reference to the friend, add it to their corresponding friendsList..
Now you have your graph.. Just run a BFS(Lookup Wikipedia) ...
Thats all you need to do...
The level at which meet is your degree of connection.
Use BFS.
Consider people as nodes. And their friendship as an edges between the nodes.
To improvise on the algorithm, run BFS from Both ends, and some kind of book keeping, like a Hashmap to keep track to visited nodes. ( Proof given by eugene in some previous post, If needed I will explain.)
private static int findMaxProfit(int[] arr)
{
int min = arr[0];
int max = arr[0];
int maxProfit = max - min;
for(int i = 0; i < arr.length; i++)
{
if(arr[i] < min)
{
min = arr[i];
max = arr[i];
}
if(arr[i] > max)
{
max = arr[i];
}
if(maxProfit < max - min)
{
maxProfit = max - min;
}
}
return maxProfit;
}
@CodeCracker : The idea is correct... and there will be only 2 such elements..
lets say the number of elements is 99.. Then more by than by n/3 means, (n/3 + 1), which is 34...
So there 34 + 34 = 68.. the count of the third one is going to be 31.
So that leaves the possibility of just 2 numbers.
And there is no additional memory used here.
I am sorry.. But I fail to understand the question and your approach to the problem.
How can u be certain the you WILL find the intersecting element after jumping your pointer to the difference in the length of the two list??
List 1 : Length = 10
List 2: Length = 6
The claim is that you are going to compare
List1(Element 5) with List2(Element 1), then
List1(Element 6) with List2(Element 2) and so on..
Is is not possible for any of the earlier elements from List1 to match up with any element in List 2.
For eg, List1(Element 2) to match up with another List2(Any element of List)
Thanks.
find pairs *ONE FROM EACH ARRAY*, that sum to 0.
- Bevan May 17, 2013your solutions loses this key information.