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. *
1
2
  • 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.

--

--

--

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

Recommended from Medium

What are falsy values in JavaScript?

React App with bulma.io

101+ Best jQuery Fixed Header Plugins & Tutorials with Demo

Instagram Filter Lab with RGB Colors & JavaScript (p5.js)

How to Make Your TypeScript Generic Functions Safer and Easier to Use

How to Validate Forms Data in React Using Reactrix

JavaScript Property Descriptors Enumerable, Writable & Configurable

Using NGINX to serve React Application (Static vs Proxy)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Travis Lee

Travis Lee

More from Medium

What you should know about P4 programming language& P4 programmable switch

Enhanced Object Literals in Javascript

CSS 3 — Web Font Generator, Vendor Prefix, dan Filter. by WPU

JavaScript, Version Controlling & NoSQL