A Perfectly Linear Relationship
You're cleaning a warehouse feed at Halcyon Freight before it goes into the delivery model. The team's screening rule is blunt: any pair of columns whose correlation comes out at 1 or -1 carries the same information twice, and one of them has to be dropped before the model ever sees them both. Every candidate pair goes through the same check, and most of them are nowhere near the limit.
You need the screening number for a pair so the decision is on record rather than eyeballed — the samples are small enough that a colleague could talk themselves into either answer just by looking at them.
Task: Print the Pearson correlation coefficient between the two columns, rounded to 2 decimals.
Input
Three lines. The first holds one integer n, the number of sampled rows (at least 2). The second holds the n values of the first column, separated by spaces. The third holds the n values of the second column, in the same row order. Values are decimal numbers, and neither column is constant.
Output
One line holding the coefficient, rounded to 2 decimals and printed the way Python prints a float — 1.0, never 1.00.
Example:
Input:
5
1 2 3 4 5
2 4 6 8 10
Output:
1.0
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in