DataLane

20. Weighted mean

mediumProNot started~8 minPythonImplement weighted_mean()

Asked in screens shaped like: Airbnb, Google

Return the weighted mean of values with weights, rounded to 4 decimals. Weights are positive and the same length as values.

Examples

  • Example 1

    Input: { "values": [1, 2, 3], "weights": [1, 1, 2] }
    Output: 2.25

Constraints

  • weights are positive and the same length as values

Python editor

Loading Python engine…

Ctrl/Cmd + Enter submits

Run your code to see stdout.

Pro problem

Medium problems unlock with Pro

Easy pads stay free. Medium and hard SQL and Python problems — editor, tests, hints, and solutions — open after you upgrade to Pro or coaching.

See plansPractice free easy problems
↑↓ navigate openesc close