Skip to content

Bug Report for three-integer-sum #4668

@Universe-Man

Description

@Universe-Man

Bug Report for https://neetcode.io/problems/three-integer-sum

It is possible this is not a bug and I've just missed something, however, the instructions state: "The output should not contain any duplicate triplets. You may return the output and the triplets in any order.", but I am being told I have a wrong answer when I have the right triplets, with no duplicates, in the wrong order.

I am also sure my solution is not the best solution, but I feel it should be working:

Input:
nums=[-1,0,1,2,-1,-4]

Your Output:
[[-1,0,1],[-1,-1,2]]

Expected output:
[[-1,-1,2],[-1,0,1]]

class Solution { /** * @param {number[]} nums * @return {number[][]} */ threeSum(nums) { let answer = [] let filteredAnswer = [] for (let i = 0; i < nums.length - 2; i++) { let anchor1 = nums[i] for (let j = 1; j < nums.length - 1; j++) { let anchor2 = nums[j] for (let k = 2; k < nums.length; k++) { if (i !== j && i !== k && j !== k) { if (anchor1 + anchor2 + nums[k] === 0) { let ns = [[nums[i], nums[j], nums[k]].sort((a, b) => a -b)] answer.push(ns) } } } } } if (answer.length === 0) { return answer } else { let control = [] for (let i = 0; i < answer.length; i++) { if (!control.includes(answer[i].join())) { control.push(answer[i].join()) filteredAnswer.push(answer[i]) } } return filteredAnswer } } }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy