Posts

Showing posts with the label Apple and orange

Python3 hackerRank exercise with solutions (Set 1)

Image
  1.DIAGONAL DIFFERENCE Given a square matrix calculate the absolute difference between the sum of it's diagonals. For example, 1 2 3 4 5 6 9 8 9 The left to right diagonal, 1+5+9=15 The right to left diagonal, 3+5+9=17 The absolute difference=|15-17|=2 Input format: The first line of input contain the order of the square matrix(n). The second line contain the matrix(A) of order (n). Output format: Absolute difference of matrix A Sample input: 3 5 8 9 2 5 7 1 4 6 Sample output: 1 Code: Diagonal difference - Code Input: Output: 2.APPLE AND ORANGE Sam's house has an apple tree and an orange tree.In the diagram below, the red line indicates Sam's house which is between the points 's' and 't'.The orange tree is located at point 'a' towards the left of the house and orange tree is located at the point 'b' towards the right of the house.              When a fruit falls from the tree it lands 'd' units of distance from the tree on x-axis. Ne