Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Compute Series Parallel Resistance

EasyPython00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the Python screen.

The question is on your right: Compute Series Parallel Resistance. Read through the requirements first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

You need to log in / sign up to run or submit.

Problem

Given an array of resistor values in ohms and an array of operations describing how they are connected, compute the equivalent resistance of the circuit. Each operation is one of:

  • "R i" — push resistor values[i] onto the stack
  • "S" — pop the top two resistances and replace them with their series equivalent
  • "P" — pop the top two resistances and replace them with their parallel equivalent using 1 / (1/a + 1/b)

Return the final equivalent resistance as a floating-point number. If the operations are invalid, return -1.0.

Constraints

  • 1 <= values.length <= 10^4
  • 1 <= ops.length <= 2 * 10^4
  • 1 <= values[i] <= 10^6
  • Each resistor index in "R i" must satisfy 0 <= i < values.length
  • Valid final circuits leave exactly one value on the stack

Function Signature

def equivalent_resistance(values, ops):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output