We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Functional Programming
  3. Introduction
  4. Compute the Perimeter of a Polygon

Compute the Perimeter of a Polygon

Problem
Submissions
Leaderboard
Discussions

You are given the cartesian coordinates of a set of points in a plane. When traversed sequentially, these points form a Polygon, , which is not self-intersecting in nature. Can you compute the perimeter of polygon ?

Input Format

The first line contains an integer, , denoting the number of points.
The subsequent lines each contain space-separated integers denoting the respective and coordinates of a point.

Constraints

  • No points are coincident, and polygon is obtained by traversing the points in a clockwise direction.

Output Format

For each test case, print the perimeter of (correct to a scale of one decimal place).

Note: Do not add any leading/trailing spaces or units.

Sample Input

4
0 0
0 1  
1 1  
1 0

Sample Output

4

Explanation

The given polygon is a square, and each of its sides are unit in length. , so we print on a new line.

Author

PRASHANTB1984

Difficulty

Easy

Max Score

15

Submitted By

4249

Need Help?


View discussions
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature