Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Compute Series Parallel Resistance

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Compute Series Parallel Resistance. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

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