Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
September 2, 2020 01:45 pm GMT

Daily Challenge 284 - Remove K

Task

Given a number k, find the smallest integer n such that if any k elements are removed from the set {1, 2, ..., n}, one can still find k distinct numbers among the remaining elements with sum of n.

[input] integer k
The number of elements to be removed.

[set] 2 k 10000

[output] an integer
The smallest value of n.

Example

For k = 2, the output should be 7.

The initial set is {1, 2, 3, 4, 5, 6, 7}.

No matter what 2 elements you remove, (1, 6), (2, 5), or (3, 4) will sum up to 7.

Why isn't the result 6? Because: In set {1, 2, 3, 4, 5, 6}, if we remove 2 elements (1,2), or (4,5) the remaining elements do not contain 2 elements that sum up to 6.

Tests

removeK(2)

removeK(3)

removeK(10)

removeK(25)

Good luck!

This challenge comes from myjinxin2015 on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!

Want to propose a challenge idea for a future post? Email [email protected] with your suggestions!


Original Link: https://dev.to/thepracticaldev/daily-challenge-284-remove-k-1ggj

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To