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: 1

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 17:00
The most efficient way to establish top best possible economize position is to measure
Answers: 1
question
Computers and Technology, 22.06.2019 19:20
Terri needs to insert a cover page into her document. where should she go to access the commands to do so? o insert tab, objects group o insert tab, illustrations group o insert tab, pages group o insert tab, media group submit
Answers: 1
question
Computers and Technology, 23.06.2019 02:00
Read this excerpt from helen keller’s autobiography, the story of my life. have you ever been at sea in a dense fog, when it seemed as if a tangible white darkness shut you in, and the great ship, tense and anxious, groped her way toward the shore with plummet and sounding-line, and you waited with beating heart for something to happen? i was like that ship before my education began, only i was without compass or sounding-line, and had no way of knowing how near the harbour was. "light! give me light! " was the wordless cry of my soul, and the light of love shone on me in that very hour. . the morning after my teacher came she led me into her room and gave me a doll. the little blind children at the perkins institution had sent it and laura bridgman had dressed it; but i did not know this until afterward. when i had played with it a little while, miss sullivan slowly spelled into my hand the word "d-o-l-l." i was at once interested in this finger play and tried to imitate it. when i finally succeeded in making the letters correctly i was flushed with childish pleasure and pride. running downstairs to my mother i held up my hand and made the letters for doll. i did not know that i was spelling a word or even that words existed; i was simply making my fingers go in monkey-like imitation. in the days that followed i learned to spell in this uncomprehending way a great many words, among them pin, hat, cup and a few verbs like sit, stand and walk. based on this excerpt, which words best describe helen keller?
Answers: 2
question
Computers and Technology, 23.06.2019 10:00
How do i delete my account on this because i didn't read this agreements and also i put age at xd
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, 01.12.2020 09:20
question
Mathematics, 01.12.2020 09:20
question
World Languages, 01.12.2020 09:20
question
Social Studies, 01.12.2020 09:20
Questions on the website: 13722361