Make Odd
Source: codechef
Difficulty: 1203

Make Odd
You are given two
binary
strings$A$and$B$, each of length$N$. Your task is to make your$score$odd which is initially$0$by choosing$N$elements such that:
For each index$i$($1 \leq i \leq N$), you will select either$A_i$or$B_i$.
If the character you select is equal to "1", add$1$to the$score$. If the character is "0", add nothing.
Your goal is to determine whether it is possible to make the$score$an odd number. If it is possible, print
YES
, otherwise print
NO
.
Input Format
The first line contains an integer$T$, the number of test cases.
For each test case:
The first line contains an integer$N$, the length of the strings$A$and$B$.
The second line contains$N$characters representing the binary string$A$.
The third line contains$N$characters representing the binary string$B$.
Output Format
For each test case, output on a new line
"YES"
if it is possible to make$score$an
odd
number and
"NO"
otherwise.
You may print each character of the string in either uppercase or lowercase (for example, the strings
"yEs"
,
"yes"
,
"Yes"
and
"YES"
will all be treated as identical).
Constraints$1 \leq T \leq 3 \cdot 10^5$$1 \leq N \leq 20$The sum of$N$over all test cases does not exceed$3 \times 10^5$$A_i, B_i \in \{0, 1\}$for all$i$Sample 1:
Explanation:
Test Case 1:
For index$1$, you have to add$1$to the$score$as both$A_{1}$and$B_{1}$are$1$.
For index$2$, you add$1$to the$score$if you select$A_{2}$(since$A_{2}$is equal to$1$). if you select$B_{2}$add$0$to the$score$(since$B_{2}$is equal to$0$). Thus, you can add either$1$or$0$to the score for index$2$.
Similarly, for index$3$, you have the option to add either$1$or$0$.
One possible solution is to select$A_{1}$,$A_{2}$,$B_{3}$which would result in$score$$3$.

Sample Input:
2
3
110
101
2
11
11

Sample Output:
YES
NO

C++ solution:
/*In the name of Allah, the most gracious and the most merciful.*/
#include<bits/stdc++.h>
#define fast_io ios::sync_with_stdio(0); cin.tie(0)
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define pb push_back
#define F first
#define S second
#define B begin()
#define E end()
#define rB rbegin()
#define rE rend()
#define L size()
#define l_b lower_bound
#define u_b upper_bound
#define in(v) for(auto &x:v)cin>>x
#define out(v) for(auto x:v)cout<<x<<" "
#define int long long
#define vi vector<int>
#define vpi vector<pair<int,int>>
using namespace std;

void solve(){
    int n,ans=0;cin>>n;
    string a,b;cin>>a>>b;
    int a1=count(a.B,a.E,'1');
    int b1=count(b.B,b.E,'1');
    if(a1%2 || b1%2){
        YES;
        return;
    }
    for(int i=0;i<n;i++){
        if(a[i]=='1'&&b[i]=='1')
            ans++;   
    }
    if(ans%2==0){
        for(int i=0;i<n;i++){
            if(a[i]=='1'&&b[i]=='0'){
                YES;
                return;
            }   
        }
        for(int i=0;i<n;i++){
            if(a[i]=='0'&&b[i]=='1'){
                YES;
                return;
            }   
        }
        NO;
    }
    else
        YES;
}

signed main(){
    fast_io;
    int T;cin>>T;
    while(T--)
       solve();
}

Go solution:
package main

import (
    "bufio"
    "os"
    "strconv"
    "strings"
)

func main() {
    reader := bufio.NewReader(os.Stdin)
    writer := bufio.NewWriter(os.Stdout)
    defer writer.Flush()

    tStr, _ := reader.ReadString('\n')
    t, _ := strconv.Atoi(strings.TrimSpace(tStr))

    for test := 0; test < t; test++ {
        nStr, _ := reader.ReadString('\n')
        n, _ := strconv.Atoi(strings.TrimSpace(nStr))

        a, _ := reader.ReadString('\n')
        b, _ := reader.ReadString('\n')
        a = strings.TrimSpace(a)
        b = strings.TrimSpace(b)

        singleOnes := 0
        totalOnes := 0

        for i := 0; i < n; i++ {
            if a[i] == '1' || b[i] == '1' {
                totalOnes++
            }
            if a[i] != b[i] {
                singleOnes++
            }
        }

        if singleOnes > 0 || totalOnes%2 == 1 {
            writer.WriteString("YES\n")
        } else {
            writer.WriteString("NO\n")
        }
    }
}

Java solution:
import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef
{
    public static void main(String[]args)throws IOException
    {
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
      int t=Integer.parseInt(br.readLine().trim());
      while(t-->0){
      int n=Integer.parseInt(br.readLine().trim());
      String a=br.readLine().trim();
      String b =br.readLine().trim();
      int  noChoice1=0;
      int noChoice0=0;
      for(int i=0; i<n; i++){
          if(a.charAt(i)=='1' && b.charAt(i)=='1')noChoice1++;
           if(a.charAt(i)=='0' && b.charAt(i)=='0')noChoice0++;
      }
      int choice=n-noChoice1-noChoice0;
      if(noChoice1%2==0 && choice==0){
          System.out.println("No");
      }else{
              System.out.println("Yes");
          }
      }

    
    }
}

JavaScript solution:
// your code goes here
const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

let input = [];
rl.on('line', (line) => {
  input.push(line);
}).on('close', () => {
  const testCases = parseInt(input[0]);
  let idx = 1;
  const results = [];

  for (let t = 0; t < testCases; t++) {
    const n = parseInt(input[idx]);
    idx++;
    const A = input[idx];
    idx++;
    const B = input[idx];
    idx++;

    let countTotalOnes = 0;
    let countMismatchedOnes = 0;

    for (let i = 0; i < n; i++) {
      if (A[i] === '1' || B[i] === '1') {
        countTotalOnes++;
      }
      if ((A[i] === '1' && B[i] === '0') || (A[i] === '0' && B[i] === '1')) {
        countMismatchedOnes++;
      }
    }

    if (countTotalOnes % 2 === 1 || countMismatchedOnes > 0) {
      results.push("YES");
    } else {
      results.push("NO");
    }
  }

  console.log(results.join("\n"));
});

Python solution:
# cook your dish here
for _ in range(int(input())):
    n=int(input())
    a=input()
    b=input()
    f=True
    for i in range(n):
        if a[i]!=b[i]:
            print("YES")
            f=False
            break 
    if f:
        ans=0
        for i in range(n):
            
            ans+=int(a[i])
        if ans%2==0:
            print("NO")
        else:
            print("YES")

Ruby solution:
def main
  test_cases = gets.to_i
  test_cases.times do
    n = gets.to_i
    a = gets.chomp
    b = gets.chomp
    possible = false
    
    # Check if there's any position where a and b differ
    (0...n).each do |i|
      if a[i] != b[i]
        possible = true
        break
      end
    end
    
    if possible
      puts "YES"
    else
      # Count number of '1's in a (since a and b are identical)
      count = a.count('1')
      puts count % 2 == 1 ? "YES" : "NO"
    end
  end
end

main