PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/WeRide

Expand algebraic expression with distribution

Last updated: Mar 29, 2026

Quick Overview

This question evaluates parsing of algebraic expressions, application of the distributive law, string manipulation, and algorithmic reasoning about time and extra-space complexity.

  • Medium
  • WeRide
  • Coding & Algorithms
  • Software Engineer

Expand algebraic expression with distribution

Company: WeRide

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

##### Question Given an expression of lowercase letters, '+', '*', and parentheses with no '+' outside any parentheses, return an equivalent expression containing only '+' by fully expanding all products (e.g., (a+b)*(c+d) → ac+ad+bc+bd). Achieve O( 1) extra-space complexity. Follow-up: If '+' may appear outside parentheses (e.g., a+b*c*(d+e+f)+k+m*(g+h)+i), output the fully expanded '+'-only form (a+bcd+bce+bcf+k+mg+mh+i). Provide working code that may use O(n) extra space (e.g., a stack).

Quick Answer: This question evaluates parsing of algebraic expressions, application of the distributive law, string manipulation, and algorithmic reasoning about time and extra-space complexity.

Related Interview Questions

  • Implement Several Core Algorithmic Components - WeRide (medium)
  • Validate Bracket Sequence - WeRide (medium)
  • Implement matrix multiplication and fast exponentiation - WeRide (medium)
  • Implement expression expansion to plus-only form - WeRide (Medium)
WeRide logo
WeRide
Aug 4, 2025, 10:55 AM
Software Engineer
Technical Screen
Coding & Algorithms
3
0
Question

Given an expression of lowercase letters, '+', '', and parentheses with no '+' outside any parentheses, return an equivalent expression containing only '+' by fully expanding all products (e.g., (a+b)(c+d) → ac+ad+bc+bd). Achieve O(

  1. extra-space complexity. Follow-up: If '+' may appear outside parentheses (e.g., a+b c (d+e+f)+k+m*(g+h)+i), output the fully expanded '+'-only form (a+bcd+bce+bcf+k+mg+mh+i). Provide working code that may use O(n) extra space (e.g., a stack).

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More WeRide•More Software Engineer•WeRide Software Engineer•WeRide Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.