CPP : Grand Temple

What will be the better solution to this problem, as my code is showing runtime error?
My code is:

Hello @Riankk,

You can implement the following approach:

  1. Make two vectors:
    1.1. first: to store the x coordinates provided as input.
    1.2. second: to store all the y coordinates provided as input.

  2. Sort both the vectors.

  3. Find the maximum difference between the adjacent elements of each vector as dx and dy.

  4. Print the Area by multiplying both the differences.

Note:
Observe the figure carefully, you have to subtract 1 from both dx and dy before multiplication.

Hope, this would help.
Give a like, if you are satisfied.

I was able to solve the question. But my question is how did the use of vectors instead of arrays decrease the runtime ?

Hey @Riankk,

  1. I suggested the optimal approach as asked by you.

  2. Because vectors allocate memory dynamically.
    And the reason for the run-time error is the size of your array.
    You are not satisfying the constraints specified in the question.

Runtime error can occur due to the following reasons:

  1. Invalid memory access during run-time.
  2. Accessing linked list nodes that do not exist.
  3. Dividing by zero.
  4. Large allocation of memory together/Large Static Memory Allocation.
  5. Making a silly mistake.

I have modified your code:

I hope, this would help.
Give a like if you are satisfied.