Official algorithmic problem description and constraints.
You are given two distinct non-negative integers π₯ and π¦. Consider two infinite sequences π1,π2,π3,β¦ and π1,π2,π3,β¦, where
Here, π₯βπ¦ denotes the bitwise XOR operation of integers π₯ and π¦.
For example, with π₯=6, the first 8 elements of sequence π will look as follows: [7,4,5,2,3,0,1,14,β¦]. Note that the indices of elements start with 1.
Your task is to find the length of the longest common subsegment β of sequences π and π. In other words, find the maximum integer π such that ππ=ππ,ππ+1=ππ+1,β¦,ππ+πβ1=ππ+πβ1 for some π,πβ₯1β A subsegment of sequence π is a sequence ππ,ππ+1,β¦,ππ, where 1β€πβ€π.
Detailed video explanations, mathematical intuition, and clean C++ implementation code.