subject

I got an Three Sum programming problem (Python), and able to come up a quick solution. However, after some more testing i found there seems to be a subtle bug in a test case.
Please help if you can shed some light on it.

The problem is - given an array of integer numbers, try to find the pairs of three numbers that can sum up to '0'. Examples:
array = [1, 0, -1, 2, 3, -2]
answer = [[1, 0, -1], [2, 0, -2]] # those triples add up to '0'

However, if the array is [12, 3, 1, 2, -6, 5, 0, -1, -8, 6]
answer = [[-8, 2, 6], [-8, 3, 5], [-6, 1, 5], [-1, 0, 1]] # missing this: [-6, 0, 6] ?!
code:
```
A. sort()
print(A)

result = []
r = len(A) -1

for x in range(len(A) - 2):
left = x + 1 # for each value of x, left starts one greater
# and increments from there.
while (left < r): # left < right
# sums == all three
sums = A[x] + A[left] + A[r]
if (sums < 0): left += 1
if (sums > 0): r -= 1
if not sums: # 0 is False ---> Not False == True
result. append([A[x],A[left],A[r]])

left += 1 # increment left -when find a combination

print(result)

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 09:30
My mom and i are moving and we don’t have wifi for the next week, i want to know if using a using a hotspot with unlimited data is better than using regular wifi. i’m considering cost, speed, and data sacrifices.
Answers: 1
question
Computers and Technology, 22.06.2019 18:30
Which of the following is an example of intellectual properly! oa. new version of a novelb. journal of ideasc. pages of a bookood. lines of a poem
Answers: 2
question
Computers and Technology, 23.06.2019 11:00
This chapter lists many ways in which becoming computer literate is beneficial. think about what your life will be like once you’re started in your career. what areas of computing will be most important for you to understand? how would an understanding of computer hardware and software you in working from home, working with groups in other countries and contributing your talents.
Answers: 1
question
Computers and Technology, 23.06.2019 15:00
Idon’t understand the double8 coding problem. it is java
Answers: 1
You know the right answer?
I got an Three Sum programming problem (Python), and able to come up a quick solution. However, afte...
Questions
question
Mathematics, 05.08.2021 02:40
Questions on the website: 13722362