Is my approach correct it's giving 0 output
Hey @supratik260699,
Your initial code is correct and later you have complicated the logic.
Also, you could have rather stored the elements in X[] and Y[] and then sort them individually rather using another extra space for vector.
You may see the following approach:
- 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. - Sort both the vectors.
- Find the maximum difference between the adjacent elements of each vector as dx and dy.
- 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.
1 Like