Company: Swiggy_27nov
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. You start at position 0. At the k -th step (for k = 1, 2, 3, ...), you may move exactly k units to the left or right. This move costs you k coins. Your task is to determine the minimum number of coins required to reach the target position N . The total cost is the sum of the costs of the steps taken. The key insight is to find the smallest number of steps, k , such that the total distance you can travel, T(k) = 1 + 2 + ... + k , is sufficient to reach N . The sum of the first k integers is a triangular number, calculated as T(k) = k * (k + 1) / 2 . To reach the target N , you need to find the smallest k that satisfies two conditions: The total distance must be at least the target distance: T(k) ≥ |N| . The difference between the total distance and the target distance must be an even number: (T(k) - |N|) must be even. This ensures t