Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.4 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
68b7687dded630607aceccad Challenge 46: 2nd Largest 29 challenge-46

--description--

Given an array, return the second largest distinct number.

--hints--

second_largest([1, 2, 3, 4]) should return 3.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(second_largest([1, 2, 3, 4]), 3)`)
}})

second_largest([20, 139, 94, 67, 31]) should return 94.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(second_largest([20, 139, 94, 67, 31]), 94)`)
}})

second_largest([2, 3, 4, 6, 6]) should return 4.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(second_largest([2, 3, 4, 6, 6]), 4)`)
}})

second_largest([10, -17, 55.5, 44, 91, 0]) should return 55.5.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(second_largest([10, -17, 55.5, 44, 91, 0]), 55.5)`)
}})

second_largest([1, 0, -1, 0, 1, 0, -1, 1, 0]) should return 0.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(second_largest([1, 0, -1, 0, 1, 0, -1, 1, 0]), 0)`)
}})

--seed--

--seed-contents--

def second_largest(arr):

    return arr

--solutions--

def second_largest(arr):
    unique = list(set(arr))
    unique.sort(reverse=True)
    return unique[1]