```ts
export function buildOnCallRota(roster: string[], blocked: string[][]): string[] {
  if (roster.length === 0 || !Array.isArray(blocked) || blocked.some(entry => !Array.isArray(entry))) {
    throw new Error("Invalid input");
  }
  const shiftCount = Math.ceil(blocked.length / roster.length);
  const rota: string[] = [];
  let lastStandIndex = -1;

  for (let i = 0; i < blocked.length; i++) {
    const available = roster.filter((name, index) => {
      return !blocked[i].includes(name) && index !== lastStandIndex && rota.filter(n => n === name).length < shiftCount;
    });

    if (available.length === 0) {
      throw new Error("Rota is impossible");
    }

    const nextStand = available.sort((a, b) => {
      const aShifts = rota.filter(n => n === a).length;
      const bShifts = rota.filter(n => n === b).length;
      return aShifts - bShifts || roster.indexOf(a) - roster.indexOf(b);
    })[0];

    rota.push(nextStand);
    lastStandIndex = roster.indexOf(nextStand);
  }

  return rota;
}
```