This problem has a simple O(1) solution:
n*(n+1)/2 = floor. solve for n
If floor = 100, n = 14
PS: Account for the rounding of the inequality solution
This problem has a simple O(1) solution:
n*(n+1)/2 = floor. solve for n
If floor = 100, n = 14
PS: Account for the rounding of the inequality solution
Regarding question 5, is an interviee expected to know what a Toeplitz matrix is, or is it perfectly okay to ask?
What I don't understand is, why is G(0) = 1?
and another question: isn't heapify(h) redundant?
since the first column is always going to be a minheap anyway.
how can you heapq.heapify a list of tuples? does the key become the first element of each tuple?
class Solution(object):
def hammingWeight(self, n):
res = 0
while n > 0:
res += n % 2
n /= 2
return res
@qkhhly Yes, but if he fixed it he would need to change the title.
@GreenTea211 The complexity O(n) where n is the length - aka the number of digits IS EQUAL to O(lgn) where n is the number itself.
I don't like the fact that in each iteration you call the API twice.
It's not a great design habit.