Menu

Post image 1
Post image 2
1 / 2
0

PWC 371 Subset Equilibrium (Just nod if you can hear me)

DEV Community·Bob Lied·about 1 month ago
#izELVZl8
Reading 0:00
15s threshold

Another explosive weekly challenge. And by explosive I mean exponential complexity. Let's see what we've got. First I'll adjust the background music for equilibrium ... Comfortably Numb Relax, I'll Need Some Information First You are given an array of numbers. Write a script to find all subsets where the sum of elements equals the sum of their indices. # Example 1 Input: @nums = (2, 1, 4, 3) #. Output: (2, 1), (1, 4), (4, 3), (2, 3) # Subset 1: (2, 1) Values: 2 + 1 = 3 Positions: 1 + 2 = 3 # Subset 2: (1, 4) Values: 1 + 4 = 5 Positions: 2 + 3 = 5 # Subset 3: (4, 3) Values: 4 + 3 = 7 Positions: 3 + 4 = 7 # Subset 4: (2, 3) Values: 2 + 3 = 5 Positions: 1 + 4 = 5 # # Example 2 Input: @nums = (3, 0, 3, 0) # Output: (3, 0), (3, 0, 3) # Subset 1: (3, 0) Values: 3 + 0 = 3 Positions: 1 + 2 = 3 # Subset 2: (3, 0, 3) Values: 3 + 0 + 3 = 6 Positions: 1 + 2 + 3 = 6 # # Example 3 Input: @nums = (5, 1, 1, 1) # Output: (5, 1, 1) # Subset 1: (5, 1, 1) Values: 5 + 1 + 1 = 7 Positions: 1 + 2 + 4 = 7 # # Example 4 Input: @nums…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More