Suppose we have an array A of size n, there are n unsorted floating point numbers. We want to find a contiguous subarray B such that B sums to an integer. Suppose we can use floor function at cost of O(1). Note that we need to return B if such B exists. My idea:
rsum = running sum of A(i.e. rsum[i]=A[1]+A[2]+...+A[i])
for i from 1 to n:
for j from i to n:
e = rsum[j]-rsum[i]+A[i]
if e==floor(e)
return A[i....j]
return "no such subarray"
This is an O(n^2) algorithm, is there a way to do that in o(n^2)?