Maximum Odd Binary Number

EasyMathStringGreedy

Solution

export function maximumOddBinaryNumber(s: string): string {
  const n = s.length;
 
  let bitCount = 0;
  for (const char of s) {
    if (char === '1') {
      bitCount += 1;
    }
  }
  return '1'.repeat(bitCount - 1) + '0'.repeat(n - bitCount) + '1';
}