Feature #10: Decode a Message

Implementing the "Decode a Message" feature for our "Operating System" project.

Description

In this feature, we will reverse a message digest function. The message digest function applies a subset of the operators +, -, *, and / along with some parenthesization to individual digits in the message and converts the subset into the message digest. The message will consist of four integers, each in the range [1, 9]. The message digest is also an integer.

Note: It is also possible that no combination of these operations may lead to a message digest.

We will be given the array of integers and the message digest. We will be restricted by the following rules:

  • The division operator / represents real division, not integer division.

  • We cannot use - as a unary operator. Every operation is carried out between two numbers.

  • We cannot concatenate numbers together. For example, if message = [1, 2, 1, 2], the expression "12 + 12" is not valid.

  • We cannot divide any number by 0.

  • Multiplying by 1 and adding to 0 are valid operations.

We will return true if any combination of the integers results in the message digest. Otherwise, we will return false.

Let’s look at a few examples:

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.