Partition Equal Subset Sum
Partition Equal Subset Sum
Hi young coder! Here's a fun challenge that will test your logic and problem-solving skills. Imagine you have a basket full of shiny marbles, and each marble has a magical number on it. Your mission, should you choose to accept it, is to find out if you can split all the marbles into two groups that have exactly the same total "magic number" sum.
Why is this fun? Well, it's like solving a mystery with numbers! 🕵️♀️🔍
Let's say we have marbles with the magical numbers [1, 5, 11, 5]. It is indeed possible to split these marbles into two groups, [1, 5, 5] and [11], both of which sum to 11!
But, if you have [1, 2, 3, 5], there's no way to split them into two groups with equal magic number sums, so you'll return False.
Here's a simple function you'll write to crack this cosmic code:
def can_partition(nums: List[int]) -> bool:
# your magic goes here
pass
Examples:
can_partition([1, 5, 11, 5]) # Returns: True can_partition([1, 2, 3, 5]) # Returns: False
Now, it's your turn to make the magic happen!
Inputs
Arg 1:
[1,5,11,5]Expected Output
trueActual Output