Company: capital one IITK
Difficulty: medium
Maximum profit You are given two binary strings S and Q , both of length N , made only of the characters 0 and 1 . Pick a non-empty substring S1 of S and a non-empty substring Q1 of Q with len(S1) = len(Q1) . Let X be their bitwise XOR, character by character: a position of X is 0 when the two characters agree and 1 when they differ. Reading X as a binary number with its leftmost character as the most significant bit, let X10 be its decimal value. The profit of that choice is profit = floor( len(X) / 2^X10 ) Report the largest profit over all choices of S1 and Q1 . Input Format The first line contains an integer T -- the number of test cases. Each test case is three lines: an integer N , the common length of the two strings; the binary string S ; the binary string Q . Output Format For each test case print the maximum profit on its own line. Constraints 1 <= T <= 1000 1 <= N <= 1000 The sum of N over all test cases of one input does not exceed 20000 (inferred -- the source