Uber OA
Question Details
Given array arr of length n, \uFEFFwe define function f(arr) \uFEFFas- if n=1, f(arr) = \uFEFFarr[0]; else, \uFEFFf(arr) = \uFEFFf(arr[0] ^ \uFEFFarr[1], \uFEFFarr[1] ^ \uFEFFarr[2]...., \uFEFFarr[n-2] ^ \uFEFFarr[n-1]) where ^ \uFEFFis...
Full Details
Given array arr of length n, \uFEFFwe define function f(arr) \uFEFFas- if n=1, f(arr) = \uFEFFarr[0]; else, \uFEFFf(arr) = \uFEFFf(arr[0] ^ \uFEFFarr[1], \uFEFFarr[1] ^ \uFEFFarr[2]...., \uFEFFarr[n-2] ^ \uFEFFarr[n-1])
where ^ \uFEFFis bitwise XOR operator.
For example, arr = [1, 2, 4, 8], \uFEFFn = 4
f(1, 2, 4, 8) = \uFEFFf(1^2, 2^4, 4^8) = f(3,6,12) = f(3^6,6^12) = \uFEFFf( 5, 10) = \uFEFFf(5^10) = \uFEFFf(15) = 15.
You need to answer q queries, each query you are given two integers l \uFEFFand r. \uFEFFFor each, what is the maximum of f() for all continuous subsegments of the array from l to r.
for eg.
Given Array = [1,2,4,8,16,32]
Given l = 1 and r = 4
Ans = Max(f(2), f(4), f(8), f(16), f(2,4), f(4,8), f(8,16), f(2,4,8), f(4,8,16), f(2,4,8,16))
Edit: Here is a video solution I found on YT- https://www.youtube.com/watch?v=Ssl0xXQvkHc&ab_channel=CodeNCode
About This Question
This is a reported interview question from a uber interview for a swe role during the oa round reported in 2024.
It covers the following topics: Arrays, Bit Manipulation, Sql .