American Express | Online Codility | Fraction Addition
Anonymous User
11543

Intern.

you are given 2 int arrays.

						A=[1,   2,   1]
						B=[2,   3,   3]
						
		so fractions are: 1/2, 2/3,  1/3

A is numerator, B is denominator.
so fractions are: 1/2, 2/3, 1/3
find all pairs that sum upto 1.
example:
here we have 2/3 + 1/3 = 1 so count = 1
return 1

return modulo 10^ +7 since input can be large

i did it in O(n^2) by going through it once and then computing addition of the 2 and checking if its one and updating counter.
is O(n) possible?

anyone have link to similar question on here?

Comments (11)