Move To End[Medium] C#

Move To End[Medium] C#

Approach: Start with two pointers i = 0, j = len-1, do till i < j, start from right use while to stop at non ToMove elements and check the element t i and do i++ and swap elements if i is at a toMove element

public static List<int> MoveElementToEnd(List<int> array, int toMove) {
    // Write your code here.
    int i = 0;
    int j = array.Count - 1;
    while(i < j)
    {
      while(j > i && array[j] == toMove)
      {
        j--;
      }
      if(i < j && array[i] == toMove)
      {
        Swap(i,j,array);
      }
      i++;
    }
    return array;
  }