Company: Swiggy_25nov
Difficulty: medium
Coin Step Puzzle Problem Description You are playing a puzzle where you must reach a given destination on a number line with the minimum number of coins. The rules are as follows: - You start at position 0. - At the i-th step, you may move exactly i units to the left or right, and this move costs you i coins. Your task is to determine the minimum number of coins required to reach the target position N. Examples Input: N = 4 Output: 6 Explanation: You need to find the minimum number of steps, let's say k, such that you can reach position N. The total cost will be the sum of costs for each step, which is 1 + 2 + ... + k. - Step 1: Move 1 unit (cost 1). Current position can be 1 or -1. Total cost: 1. - Step 2: Move 2 units (cost 2). Current position can be (1+2=3), (1-2=-1), (-1+2=1), (-1-2=-3). Total cost: 1+2=3. - Step 3: Move 3 units (cost 3). Total cost: 1+2+3=6. With 3 steps, the maximum reachable position is 1 + 2 + 3 = 6. To reach position 4, we can make the following moves: -1, +2