← Moloco Interview Insights

Moloco·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Coding round at Molocoads for a Software Engineer role. One algorithmic problem on balanced parentheses scoring. Pretty focused session, nothing too wild.

Questions Asked (1)

Q1

Given a balanced parentheses string, compute its score using these rules: '()' equals 1, two adjacent balanced strings AB score A + B, and a balanced string wrapped in parentheses (A) scores 2 times A.

Algorithms & Data Structures
Author's notes

My first instinct was recursion and I think that was the right call, but I spent too long second-guessing whether a stack-based approach would be cleaner.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem and walk through a simple example to confirm understanding. Then present a stack-based solution that processes each character, using a stack to keep track of scores at each depth, and finally analyze time and space complexity.

Pro tip: Mention that the stack approach can be optimized to O(1) space by using a depth counter and a running score, but only if the interviewer wants to see optimization. Also, discuss edge cases like empty string and deeply nested parentheses.

1. Understand the problem

Restate the scoring rules and confirm with the interviewer. Walk through a small example like '(()(()))' to ensure alignment.

2. Choose an approach

Decide between stack-based and depth-counting methods. Explain why stack is intuitive for nested structures.

3. Implement the solution

Write clean code with clear variable names. For stack: push 0 for each '(', and on ')' pop and compute score, then add to new top.

4. Analyze complexity

State that time complexity is O(n) and space complexity is O(n) for stack, or O(1) if optimized.

5. Test and discuss edge cases

Run through examples like '()', '()()', '(())', and empty string. Mention potential optimizations if asked.

Key Points to Mention

  • Stack-based approach: push 0 for each '(', on ')' compute score and add to new top.
  • Depth-counting optimization: maintain current depth and total score, using a stack or array to store scores at each depth.
  • Time complexity O(n) and space complexity O(n) for stack, O(1) for optimized version.
  • Handling of adjacent balanced strings: sum scores.
  • Handling of nested balanced strings: multiply inner score by 2.
  • Edge cases: empty string, single pair, deeply nested, and multiple adjacent pairs.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.