Can somebody help me out with the code here ?
My approach uses 2 sets s1 and s2 of integer values which contain all the possible differences you can get by taking pairs(0...i) and also an array diff which contain abs difference of a pair of books. s2 is just used to make new set and then reassign it to s1.
So, according to my algorithm
- (3, 5) -> diff[0] = 2 : s1(2)
- (7, 11) -> diff[1] = 4 : s1(2, 6) // i.e. (|4 - 2|, 4 + 2)
- (8, 8) -> diff[2] = 0 : s1(2, 6)
- (2, 9) -> diff[3] = 7 : s1(1, 5, 9, 13) // i.e. (|7 - 2|, 7 + 2, 7 + 6, |7 - 6|)
And we get ans as 1. The summation term in mod is only added to the set for sum <= 299 which is max difference. I'm get...
Read more… (171 words)