gumanji
BAN USER
Assuming we are given parent pointer in the tree:
Apply DFS from the leaf node (including the parent), add 1 ms for all nodes in your path until you reach end and recurse back to node where you started. Node keeps max cost after recursive return to itself, and returns that to its calling node. Once reached back to the leaf node, returned cost is the answer.
Solution O(N) psuedo code:
Since all start times are sorted, we can iterate through to find subsequent working slots and compare with max found so far. return max
psuedo:
log {
timeStamp start;
timeStamp end;
}
getMaxWorkingSlot(log[] logs) {
int maxNotIdle=0 //seconds
log previous;
for (log l : logs) {
if (previous==null)
previous = l;
maxNotIdle = l.end-l.start;
continue;
if (l.start>previous.end)
previous = l;
if (maxNotIdle<l.end-l.start)
maxNotIdle=l.end-l.start;
else
if (l.end>previous.end)
previus.end=l.end;
int notIdle = previous.end – previous.start
if (notIdle>maxNotIdle)
maxNotIdle=notIdle;
}
return maxNotIdle;
}
Repjuanitajboon, Applications Developer at 247quickbookshelp
Hi everyone, I am from Pelham. I currently work in the Hechinger as Cashier.I like to do creative things ...
Repdalejohnson762, Accountant at ABC TECH SUPPORT
I have exceptionally skilled Journalists possessed dogged determination to find the new story and deliver it to the public. I ...
Repgradyjvierra, Animator at Alliance Global Servies
Je suis Grady de Phoenix USA. Je travaille en tant que technicien de laboratoire clinique dans la société Samuels Men ...
Repkathyrnunez, Area Sales Manager at Advent
I am manager in a Star Bright Investment Group company. I like to solve puzzles for Has excellent problem-solving and ...
Reppaulaamontalvo, AT&T Customer service email at AMD
I am working as Human Resources Associates, and my duties are for obtaining, recording, and interpreting human resources information within ...
Repkennypmillerk, AT&T Customer service email at 247quickbookshelp
My name is Kenny and I am working as a trusted investor in Pittsburgh USA.I identify / set up a ...
Repmarkemorgan007, Applications Developer at Big Fish
I am Mark From Fresno city in USA.I working as a tour guide and also help for make a ...
Using O(n) space,
- gumanji August 24, 2017store integers in a hash which has number as the key, and contains no. of consecutive elements smaller than, and no. of consecutive numbers greater than that.
For each number in array, search smaller and larger numbers, then store it updating its own smaller than & greater than values.
keep track of max consecutive sequence, consecutive smaller + larger + number.
That's your answer in O(n) and O(n) space.
Radix sort answer above will also take O(n) space and run slightly slower.