• + 0 comments

    here is my c# solution ,

    public static List<int> permutationEquation(List<int> p)
        {
    		// Sort the list and keep track of the original indices
            var sortedListWithIndices = p
        .Select((value, index) => new { Value = value, OriginalIndex = index + 1 })
        .OrderBy(x => x.Value)
        .ToList();
    
    // Create a list to store the transformed indices
    var tempList1 = sortedListWithIndices
        .Select(x => x.OriginalIndex)
        .ToList();
    
    // Create a list to store the final result
    var tempList2 = tempList1
        .Select(index => p.IndexOf(index) + 1)
        .ToList();
    
    return tempList2;
        }