Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You have an array 'A of 'N' digits from '0' to '9'. You need to create the largest possible number divisible by '30' using the

You have an array 'A of 'N' digits from '0' to '9'. You need to create the largest possible number divisible by '30' using the elements of the array. You can use each element of the array at most once.

Your task is to return the largest number in string format. Return -1 it is not possible to create a number Divisible by 30.

Example:

'N' = 4

'A' = [0, 0, 3, 4]

By choosing the elements at the indices '2', '0', and '1', we can create the number '300', which represents largest number which is divisible by '30'.

Detailed explanation (Input/output format, Notes, Images)

Input Format:

The first line contains an integer, 'N' denoting the number of elements of the array 'A'. The following line contains 'N' space-separated integers denoting the elements of the array 'A'.

Output Format:

For each test case, output the string as described above.

Note:

You don't need to print anything. Just implement the given function.

Sample Input 1: 2 5 1 5 9 4 0 2 1 1 Sample Output 1: 9540 -1 Explanation of sample input 1:

For test case 1:

If you skip the "Oth' element and take all the remaining elements, you can create the number '9540' which is divisible by '30'. Therefore, we return '9540' as our answer.

For test case 2:

Here, you can either create '1' or '11'.

None of them is divisible by '30'.

Therefore. we return '-1'.

Sample Input 2: 2 5 3 9 8 1 0 4 1 2 5 0 Sample Output 2: 98310 510

def super30(n: int, a: List[int]) -> Union[str, int]:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Compute present values. LO15

Answered: 1 week ago

Question

Explain the factors that determine the degree of decentralisation

Answered: 1 week ago

Question

What Is acidity?

Answered: 1 week ago

Question

Explain the principles of delegation

Answered: 1 week ago

Question

State the importance of motivation

Answered: 1 week ago

Question

Discuss the various steps involved in the process of planning

Answered: 1 week ago