P2169 - Editorial

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4

Author: pols_agyi_pols
Tester: kingmessi
Editorialist: iceknight1093

DIFFICULTY:

Cakewalk

PREREQUISITES:

None

PROBLEM:

You’re given a binary string S. Find any binary string T such that S_i \neq T_i for all i.

EXPLANATION:

Since we’re working with only binary strings, the answer is unique: just replace every 0 with 1 and vice versa; and print the resulting string.

TIME COMPLEXITY:

\mathcal{O}(N) per testcase.

CODE:

Editorialist's code (PyPy3)
for _ in range(int(input())):
    n = int(input())
    s = input()
    t = ''
    for c in s:
        if c == '0': t += '1'
        else: t += '0'
    print(t)