Combination Sum II - Leetcode 40 - Java

preview_player
Показать описание
Combination Sum II - Leetcode 40 - Java

--------------------------------ABOUT--------------------------------
🧑🏻 My name is David and I am a software engineer at Meta. My passion is teaching software devs how to pass the grueling technical interviews to help them land their 6-figure dream tech job.

I have received 3 six-figure offers from Google, Meta, and Amazon.

🔬I provide content that will allow you to understand the thought process, pseudocode, time complexity, and code when approaching coding problems.

--------------------------------SOCIAL--------------------------------

💬 If you have any topic or questions you want me to cover, let me know in the comment section below ~ ฅʕ•ᴥ•`ʔ ฅʕ•ᴥ•`ʔ ฅʕ•ᴥ•`ʔ

#technicalinterview #techcareer #softwareengineer
Рекомендации по теме
Комментарии
Автор

This solution makes no sense to me to be honest because I guess I have a misunderstanding with the problem statement.
it says no duplicates allowed...so I agree that we must sort the candidates list so we can check if candidates[j-1] == candidates[j]
but on the test cases we have : candidates = [10, 1, 2, 7, 6, 1, 5], target = 8
Output:
[
[1, 1, 6],
[1, 2, 5],
[1, 7],
[2, 6]
]

If we sorted candidates = [1, 1, 2, 5, 6, 7, 10], then we shouldn't include candidate[1] in our consideration because candidate[1] == candidate[0]
but in the output we see that [1, 1, 6] is an allowable answer...but if we were to skip candidate[j] as outlined in the code then this is not possible...ugh

matthewzarate
welcome to shbcf.ru