chandransuraj
BAN USERBy the way its me(chandransuraj) posted by mistakes as anonymous
- chandransuraj August 04, 2011I think most guys have forgot to optimize it. Consider this. Suppose I have to sum up to 20 and the current node value is 10. Then I can simply ignore the entire right subtree because and value 'X' in the right subtree must be greater than 10 and hence 10 + X > 20. So the solution will not include any node form right sub tree. This concept can be applied recursively and will greatly reduce the overall time.
- chandransuraj March 18, 2011Hash all the elements of first list into a hashtable.
Iterate through the second list and check for it in the hash, if already there then add the element in to the third list.
Note that though the expected time for this is O(n), the worst case is still O(n^2). So we can also use a BST instead of hash to better it to O(log n)
1) Use two pointers a and b.
2) Set both of them to the start of the text
3) While end is not reached, keep incrementing b until it hits a space/punctuation.
4) When it does hit a space or punctuation, set a = b and increment count by 1, and go back to step 3
The final value of count is our answer.
(Note that you might need to tweak it a little to support strings consequent punctuations)
hmm..
- chandransuraj February 15, 2011Wrong. See my comments on ganjiayan's answer
- chandransuraj February 11, 2011Wrong, because:
1) The number returned is between 0 and 3
2) The number returned will not be random
This is not correct. Reason:
The expression rand5() + rand5() will return a value between 0 and 10. Consider two groups on this [0-7] and [8-10].
Now when rand5() + rand5() lies is 2nd group(8-10) , then your method returns a value in [0-2]. Hence the probability of occurrence of of [0-2] is higher than other numbers. Consequently its not random.
This is not correct. As your rand7() method will always return a number divisible by (5/7). Consequently the probability of occurrence any number that is not divisible by 5/7 is 0.
- chandransuraj February 11, 2011If we encounter a space, just increase the word-count by 1 unless the previous character was also a space
- chandransuraj February 08, 2011I think it's pretty simple.
Need to consider only three possibilities.
1) Numbers are arranged alternatively as in x1-U-x2-U-x3-U..
2) Number is of the form U-x1-x2-U
3) Any other combination.
Now we need to do only this:
While iterating each element check whether:
a) its equal to its next value, or
b) its equal to its next to next value, or
c) its equal to its next to next to next value.
Hence O(n)
Consider all the start and end points in the intervals as elements of a sorted array. Now simply apply a binary search on it. o(n log n)
This is of course assuming that the intervals are given to you as sorted.
the question does not say that the arrays are sorted
- chandransuraj February 07, 2011An ugly number is a number that has only 2, 3 or 5 as prime factors, i.e any number that can be represented as 2^x * 3^y * 5^z where x,y and z are positive integral values. Note that this definition allows for 1 to be an ugly number for x=0, y=0 and z=0.
- chandransuraj February 07, 2011Create a trie from all the words in all the files. Every time a word's leaf is reached store the paragraph-index and the file-index in it.
Using this a word can be searched in o(m) where m is the length of the word.
RepLoriKetron, Accountant at Aspire Systems
I am a content marketing professional at HubatSpot, an inbound marketing and sales platform that helps companies attract visitors, convert ...
Never mind
- chandransuraj August 06, 2011