DEV Community

dev.to staff
dev.to staff

Posted on

7

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 yo+challenge@dev.to with your suggestions!

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay