namespace LeetCode.Logic;

public class TwoSum
{
    /// <summary>
    /// Finds the indices of two numbers in the input array that add up to the specified target value.
    /// Input: nums = [3,2,4], target = 6
    /// Output: [1,2]
    /// </summary>
    /// <param name="nums">An array of integers to search within.</param>
    /// <param name="target">The target sum to achieve by adding two numbers from the array.</param>
    /// <returns>
    /// An array containing the indices of the two numbers that add up to the target value.
    /// If no such pair exists, the returned array may contain default or incomplete values.
    /// </returns>
    public int[] Indices(int[] nums, int target)
    {
        var result = new int[nums.Length];
        var index = 0;
        
        for (var i = 0; i < nums.Length - 1; i++)
            for (var j =  nums.Length - 1; j > 0; j--)
        {
            if (nums[i] + nums[j] <= target)
            {
                result[index] = i;
                result[index++] = j;
            }
        }

        return result.Take(index + 1).Order().Distinct().ToArray();
    }
}