@Sukesh Not sure what's troubling you. Just use binary search.
StefanPochmann
@StefanPochmann
No, seriously, my name really is Stefan. Not Stephan, Stephen, Steven or even Stefen.
Posts made by StefanPochmann

RE: Don't treat it as a 2D matrix, just treat it as a sorted list

RE: Is there's a O(log(m)+log(n)) solution? I know O(n+m) and O(m*log(n))
@greenflag What's your point? I don't see what that has to do with this thread...

RE: Is it a simple code(C++)?
@Leoaqr Instead of
if digits[0] == 0:
you could useelse:
. 
Oneliner Python
Just comparing sums...
def findErrorNums(self, nums): return [sum(nums)  sum(set(nums)), sum(range(1, len(nums)+1))  sum(set(nums))]

Oneliner Python
def countSubstrings(self, s): return sum(s[i:j] == s[i:j][::1] for j in range(len(s) + 1) for i in range(j))

RE: 7 lines, iterative, real O(1) space
@happykimi Not sure what you mean. I am considering that case. Did you overlook my
and root.left
? 
Short and fast Python
Just implementing the binary search solution using NumPy for brevity and efficiency. Gets accepted in about 260 ms, easily beating 100% in the current runtime distribution (where times range from 439 ms to 1892 ms).
import numpy as np class Solution(object): def findMaxAverage(self, nums, k): lo, hi = min(nums), max(nums) nums = np.array([0] + nums) while hi  lo > 1e5: mid = nums[0] = (lo + hi) / 2. sums = (nums  mid).cumsum() mins = np.minimum.accumulate(sums) if (sums[k:]  mins[:k]).max() > 0: lo = mid else: hi = mid return lo

RE: Exceptionally fast Python
@RootM7 Nonsense. My code correctly returns
False
for that. Looks like you're confusing node values and nodes. It doesn't even matter what the values are, as I'm ignoring them. 
RE: "Reservoir sampling" seems inefficient
@parvez.h.shaikh said in "Reservoir sampling" seems inefficient:
I compute length
Where? I don't see it.
Also why dwell in specific random number generation when they're present in libraries :)
Huh? I am using a library function. And a more appropriate one than you are. You're the one making it complicated.