LeetCode 1310. XOR Queries of a Subarray in F#
URL
XOR Queries of a Subarray - LeetCode
Code
let xorQueries (arr: int list) (queries: (int * int) list) : int list =
let rec xorQueries' queries (arr: int[]) acc =
match queries with
| [] -> List.rev acc
| (s1, e1) :: t -> xorQueries' t arr ((arr.[e1 + 1] ^^^ arr.[s1]) :: acc)
let arr =
arr
|> List.fold (fun acc n -> ((List.head acc) ^^^ n) :: acc) [ 0 ]
|> List.rev
|> List.toArray
xorQueries' queries arr []