HackerRank Solution | Apple And Orange

HackerRank Solution | Apple And Orange

Apple and Orange Problem Statement

Sam's house has an apple tree and an orange tree that yield an abundance of fruit. Using the information given below, determine the number of apples and oranges that land on Sam's house.
In the diagram below:

  • The red region denotes the house, where s is 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 units of distance d 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. *
Given the value of d for m apples and n oranges, determine how many apples and oranges will fall on Sam's house (i.e., in the inclusive range [m,n])?


Apple and Orange Solution Code

Note: These solutions are absolutely not the most optimized and effecient one. These are very beginner style approach and was solved without prior knowledge of CS concepts like DataStructures and Algorithms that are usually taught in colleges.

Python Code

Post a Comment

0 Comments