Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Remove Redundant Parentheses

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Remove Redundant Parentheses. Start with the requirements and the two tables 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

Explain how you would remove redundant parentheses from an expression.

The expressions are stored as text. For this task, parentheses are redundant only when they directly enclose a single identifier or integer operand. Preserve parentheses around compound expressions and exclude inactive or null expressions.

Output

  1. One row per eligible expression, with expression_group, expression_id, and cleaned_expression
  2. Sort by expression_group ascending, then expression_id ascending

Schema

expression_groups
ColumnTypeDescription
group_idPKINTUnique group identifier
expression_groupVARCHAR(50)Display name for the expression group
expressions
ColumnTypeDescription
expression_idPKINTUnique expression identifier
group_idINTAssociated expression group
expression_textTEXTExpression stored as text
is_activeBOOLEANWhether the expression should be processed
Tablesexpressionsexpression_groups
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results