Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Problem: Zeropocalypse ( This is a trending question of the week where many coders across the world are solving it as a challenge in

JAVA
Problem: Zeropocalypse (This is a trending question of the week where many
coders across the world are solving it as a challenge in the best optimal way. The
program is required to be run for various input testcases but in our course, you
are expected to run the code at least for the input testcase mentioned in this
homework.)
Task:
In a land where numbers hold the key to order, there exists an array of size N. This array
contains numbers ranging from 0 to 10.
The challenge is to replace all the zeros in this array with positive integers while ensuring
that every subsequence of the final modified array is strictly increasing.
If there are a finite number of ways to do so, you must print the total number of such ways.
Input format
For each test case:
The first line contains N denoting the size of array A.
The second line contains N space-separated integers, denoting the elements
of A.
Output format
For this test case, print in a new line the number of ways to replace all the zeros with
positive integers in such a way that the above condition is satisfied.
Sample Input
4
\table[[1,0,0,5]]
Sample Output
3
Explanation
For test case 1:
N=4
A=[1,0,0,5]
The following are the final modified arrays that can be obtained by replacing O's with
positive integers such that every subsequence of the final modified array is strictly
increasing:
1,2,3,5
1,3,4,5
1,2,4,5
Thus, the answer is 3.
So, Create 2 classes Zeropocalypse and Testmain. Create a method
Zeropocalypse_ways() in Zeropocalypse class.
Create the array of size 4 in Testmain class. Take the numbers from the user using
Scanner.
In the Testmain class, create object for Zeropocalypse class and call the method
Zeropocalypse_ways () using the object. You will receive the return integer value
from Zeropocalypse_ways 0 in Testmain class and print the result. You can add
other helper methods if you need to keep the code more organised.
When you are running the code, please test for the given values in this testcase
above.
image text in transcribed

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

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions