Skip to content

Bug Report for merge-triplets-to-form-target #4682

@LinditaKalaj

Description

@LinditaKalaj

Bug Report for https://neetcode.io/problems/merge-triplets-to-form-target

Solution was accepted when It shouldn't be.

`class Solution:
def mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool:
t1 = t2 = t3 = 0
t1min = triplets[0][0]
t2min = triplets[0][1]
t3min = triplets[0][2]

    for x, y, z in triplets:
        if x == target[0]:
            t1 += 1
        if y == target[1]:
            t2 += 1
        if z == target[2]:
            t3 += 1
        t1min = min(t1min, x)
        t2min = min(t2min, y)
        t3min = min(t3min, z)

    if not t1 or not t2 or not t3:
        return False
    res1 = res2 = res3 = False
    if t1 > 1 or (t1 == 1 and target[0] > t1min) or len(triplets) == 1:
        res1 = True
    if t2 > 1 or (t2 == 1 and target[1] > t2min) or len(triplets) == 1:
        res2 = True
    if t3 > 1 or (t3 == 1 and target[2] > t3min) or len(triplets) == 1:
        res3 = True
    
    return res1 and res2 and res3
        
        
    `

This solution was accepted, but when I introduce a test case like so:
triplets=[[1,5,3], [7,2,1], [1,1,1]] target=[7,2,3]

It fails the test case. Add this as a test case?

Image

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