Amazon Online Assessment 2021 (OA) - Find Valid Discount Coupons

At Amazon's annual sale. employees are tasked with generating valid discount coupons for loyal customers. However, there are some used/invalid coupons in the mix and the challenge in this task is to determine whether a given discount coupon is valid or not.

The validity of a discount coupon is determined as follows:

  1. An empty discount coupon is valid.
  2. If a discount coupon A is valid, then a discount coupon C made by adding one character x to both the beginning of A and the end of A is also valid (i.e the discount coupon C = xAx is valid).
  3. If two discount coupons A and B are vand, then the concatenation of B and A is also valid (i.e the coupons AB and BA are both valid).

Given n discount coupons, each coupon consisting of only lowercase English characters, where the ith discount coupon is denoted discounts[i], determine if each discount coupon is valid or not. A valid coupon is denoted by 1 in the answer may while an invalid coupon is denoted by 0.

Input

  • discounts: Array of discount coupons.

Output

Array of integers, a valid coupon is denoted by 1 and an invalid coupon is denoted by 0.

Examples

Example 1:

Input:

1discounts = ['abba', 'abca']

Output: [1, 0]

Explanation:

'abba' is valid and 'abca' is invalid.

Try it yourself

Solution

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