Apple and Orange Solution in Javascript

• The red region denotes the house, where is s the start point, and t is the endpoint. The apple tree is to the left of the house, and the orange tree is to its right.
• Assume the trees are located on a single point, where the apple tree is at point a, and the orange tree is at point b.
• When a fruit falls from its tree, it lands d units of distance from its tree of origin along the x-axis. *A negative value of d means the fruit fell d units to the tree’s left, and a positive value of d means it falls d units to the tree’s right. *
`12`
• s: integer, starting point of Sam’s house location.
• t: integer, ending location of Sam’s house location.
• a: integer, location of the Apple tree.
• b: integer, location of the Orange tree.
• apples: integer array, distances at which each apple falls from the tree.
• oranges: integer array, distances at which each orange falls from the tree.
• 1 ≤ s,t,a,b,m,n ≤ 10⁵
• -10⁵ ≤ d ≤ 10⁵
• a < s < t <b
1. The first integer: the number of apples that fall on Sam’s house.
2. The second integer: the number of oranges that fall on Sam’s house.

--

--

--

More from Travis Lee

Love podcasts or audiobooks? Learn on the go with our new app.