ashishgopalhattimare
BAN USER
Comments (4)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
def maximumSum(arr):
excl, incl = 0, arr[0]
for i in range(1, len(arr)):
new_excl = max(incl, excl)
incl = excl + arr[i]
excl = new_excl;
return max(incl, excl)
Comment hidden because of low score. Click to expand.
0
of 0 vote
What should be the compexity of this question?
Is it an NP hard problem?
Comment hidden because of low score. Click to expand.
0
of 0 vote
collect only distinct elements and then sort the array.
Complexity : O(nlogn) time and O(n) space
i, count = 1, 1
while(i < len(nums)):
if(A[i-1] == A[i]-1):
count += 1
if(count == 5) return true
else:
count = 1
return false
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
- ashishgopalhattimare July 10, 2019