Question: array arr of a positive integers and an integer vali. We can perform the following tion of the given array arrat most once. The operation

array arr of a positive integers and an integer vali. We can perform the following tion of the given array arrat most once. The operation is as follows:
Choose two indices left and right such that left s right and right s n(1-based inderings.
For each value in the range of indices lefr and right, bit-wise xor each of them with m( mba non-negative integer which you can choose as per your subarray). More formally numsin wit change to (numsin) xor m).
Find the maximum possible frequency of valafter performing the operation at most once.
Example
Suppose n=3, arr =[7,2,3],val=2
There are 6 possible (left right) pairs such that left s right and right:s n
(1:1) We can use in =5. The resultant acray wil be 2,2,3.(Frequency of vat is 2)
(1,3) We can use m=0. The resulbat array will be [7,2.3](Erequency of val is 1)
(2.2)- We can use m=a. The resuttant arraycwi be [7: 2,3].(Frequency of val is 1)
(2,3)** We can use m=0. The resuitant array wall the ,3).(Frequency of x s. is 1. write code in cpp
 array arr of a positive integers and an integer vali. We

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!