arsragavan
BAN USER- 1of 1 vote
AnswersYou are given a file which contains 3 values - start time, end time, amount of water flowing between the start time and end time for one day
- arsragavan in United States
The start time and end time may overlap and are inclusive. The times are not in a sorted order
Example:
0,10,100
10,15,300
16,20,400
5,15,200
Find the max flow of water at any instant of time.
In the above example, the answer is 600 ( at instant 10)| Report Duplicate | Flag | PURGE
A9 Intern Algorithm
The suggested method takes O(n) time for reversing the elements..
In java, we can use subList method of ArrayList class. I guess it takes constant time...
List<Integer> list1 = list.subList(0, 4);
list = list.subList(4, 9);
list.addAll(list1);
Can anyone confirm ?
- arsragavan March 04, 2014In the reverse function,
1) pop the elements one by one from Stack s and push into Stack t.
2) Assign Stack s = Stack t
3) Return Stack s;
public int kDistanceAboveNode(Tree root, Tree node, int k) {
if (root == null)
return Integer.MIN_VALUE;
if (root == node) {
return 0;
}
int lD = kDistanceAboveNode(root.left, node, k)+1;
int rD = kDistanceAboveNode(root.right, node, k)+1;
if (lD == k || rD == k)
System.out.println("Kth distance above node = "+root.value);
return Math.max(lD, rD);
}
Repleroydperry, Backend Developer at AppNexus
I am from the USA. I am 27 year old. I drive the train for my company Monk Home Funding ...
Repsharonpkarr, None at BT
Hi! My name is Mary. I am a writer for a variety of web and multi-platform applications.I am a ...
Reppaynealiciam, Apple Phone Number available 24/7 for our Customers at Adap.tv
Hello I am Sarah Cote, and I live in Missouri, USA. Last year, Web trailblazer. Passionate entrepreneur. Subtly charming bacon ...
There are many ways to do it.. One simple technique is
- arsragavan March 05, 20141) Traverse to the middle node
2) Seperate the list starting from the next node of middle node.
So now you will have two list...
List1 - header to middle node
List2 - next of middle node to tail
3) Do a two- way merge on List1 and List2
complexity: O(n), n is the total no of nodes in the list,
space; O(1) - I don't think making a list into two halves is an extra space. So, it takes constant space... I'm not 100 % sure about this. Can any one confirm..