AREAPERI - Editorial

Problem Link - Area OR Perimeter Practice Problem in 500 to 1000 difficulty problems

Problem Statement:

Write a program to obtain length (L) and breadth (B) of a rectangle and check whether its area is greater or perimeter is greater or both are equal.

Approach:

  • Computation:
    • Compute the area as Area = L * B.
    • Compute the perimeter as Perimeter = 2 * (L + B).
  • Comparison:
    • Compare the area with the perimeter:
      • If Area > Perimeter, print “Area” and the value of the area.
      • If Perimeter > Area, print “Peri” and the value of the perimeter.
      • If both are equal, print “Eq” and the value.

Complexity:

  • Time Complexity: The time complexity is O(1) since the computation involves simple arithmetic operations (multiplication and addition) which are constant-time operations.
  • Space Complexity: The space complexity is O(1) as the program only uses a few variables.