"we can use two pointer + set like maintain i,j and also insert jth character to set like while set size is equal to our window j-i+1 then maximize our answer and increase jth pointer till last index"
Kishor J. - "we can use two pointer + set like maintain i,j and also insert jth character to set like while set size is equal to our window j-i+1 then maximize our answer and increase jth pointer till last index"See full answer
"
Brute Force Two Pointer Solution:
from typing import List
def two_sum(nums, target):
for i in range(len(nums)):
for j in range(i+1, len(nums)):
if nums[i]+nums[j]==target:
return [i,j]
return []
debug your code below
print(two_sum([2, 7, 11, 15], 9))
`"
Ritaban M. - "
Brute Force Two Pointer Solution:
from typing import List
def two_sum(nums, target):
for i in range(len(nums)):
for j in range(i+1, len(nums)):
if nums[i]+nums[j]==target:
return [i,j]
return []
debug your code below
print(two_sum([2, 7, 11, 15], 9))
`"See full answer
"I've worked on projects not quite like this, but very similar, in the past - I'll borrow from that to answer this:
The Broader Context
this problem doesn't specify the type of data we're working with, or how it's being ingested
to align with my personal background, I'll assume a picture that lends this problem well to being a computer vision (abbreviated "CV") related question:
let's say we have a conveyor belt in a waste facility, which sequentially carries a stream of waste
w"
Zain R. - "I've worked on projects not quite like this, but very similar, in the past - I'll borrow from that to answer this:
The Broader Context
this problem doesn't specify the type of data we're working with, or how it's being ingested
to align with my personal background, I'll assume a picture that lends this problem well to being a computer vision (abbreviated "CV") related question:
let's say we have a conveyor belt in a waste facility, which sequentially carries a stream of waste
w"See full answer
"
O(n) time, O(1) space
from typing import List
def maxsubarraysum(nums: List[int]) -> int:
if len(nums) == 0:
return 0
maxsum = currsum = nums[0]
for i in range(1, len(nums)):
currsum = max(currsum + nums[i], nums[i])
maxsum = max(currsum, max_sum)
return max_sum
debug your code below
print(maxsubarraysum([-1, 2, -3, 4]))
`"
Rick E. - "
O(n) time, O(1) space
from typing import List
def maxsubarraysum(nums: List[int]) -> int:
if len(nums) == 0:
return 0
maxsum = currsum = nums[0]
for i in range(1, len(nums)):
currsum = max(currsum + nums[i], nums[i])
maxsum = max(currsum, max_sum)
return max_sum
debug your code below
print(maxsubarraysum([-1, 2, -3, 4]))
`"See full answer
Machine Learning Engineer
Data Structures & Algorithms
+4 more
🧠Want an expert answer to a question? Saving questions lets us know what content to make next.