Amazon Online Assessment 2021 (OA) - Matching Brackets

Kindle Direct Publishing, Amazon's e-book selfpublishing platform, is working on a new feature to help authors use special text characters in different ways. They have asked for your help in beta testing a new part of the feature involving round and square brackets. Given a string that consists of characters (, ), [, ] and ?, determine how many ways it can be split into two non-empty substrings such that the characters in each substring can be rearranged into a balanced string.

A sequence of round and square brackets can be rearranged into a balanced sequence if and only if the number of opened and closed bracket is equal for both types of the brackets. The question marks can take the place of any needed character, and the substrings together must contain the entire string.

Solution and Explanations

Title

Script

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Contrary to popular belief, Lorem Ipsum is not simply random text.

1  >>> a = [1, 2, 3]
2  >>> a[-1]
3  3

Get premium for instant access to all content and solutions

Upgrade