Reverse each number in a list I have this method which reverses a list of numbers. For example, if the given input is { 1232, 3455, 6071 }, it will return {2321, 5543, 1706}

public static List&lt;int&gt; ReverseIntegerList_Array(List&lt;int&gt; intList)
    {
        var newIntList = new List&lt;int&gt;();

        foreach (var numbers in intList)
        {
            var charNums = numbers.ToString();
            char[] arrNums = new char[charNums.Length];
            for (int x = 0; x &lt; charNums.Length;x++)
            {
                arrNums[x] = charNums[charNums.Length-1-x];
            }
            newIntList.Add(Convert.ToInt32(string.Join("",arrNums)));

        }
        return newIntList;
    }


Can I reduce the space complexity further by not using an extra list object to store the result and return the result by overwriting the existing list object (defined in the method parameter)?

Found the way already.

 public static List&lt;int&gt; ReverseIntegerList_Array3(List&lt;int&gt; intList)
    {
        // var newIntList = new List&lt;int&gt;();
        for (int i = 0; i &lt; intList.Count; i++)
        {

            var charNums = intList[i].ToString();
            intList[i] = 0; // Clear it. 
            char[] arrNums = new char[charNums.Length];
            for (int x = 0; x &lt; charNums.Length; x++)
            {
                arrNums[x] = charNums[charNums.Length - 1 - x];
            }
            intList[i] = Convert.ToInt32(string.Join("", arrNums));
        }

        return intList;
    }


Is this solution okay in regards to space complexity?
You can improve the efficiency by reversing the numbers as integers instead of converting to strings and back.

Modifying the list and returning it is redundant since the list is passed by reference and your changes will persist to the original list.

Simplified your code could look like this:

public static void ReverseIntegerList_Array(List&lt;int&gt; intList)
{
    if(intList == null)
    {
        return;
    }
    int limit = intList.Count;
    for(int i = 0; i &lt; limit;++i)
    {
        intList[i] = ReverseNum(intList[i]);
    }
}

public static int ReverseNum(int num)
{
    int retVal = 0;
    while(num &gt; 0)
    {
        retVal = (retVal * 10) + num % 10;
        num /= 10;
    }
    return retVal;
}