Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 9 Max. score: 2 0 . 0 0 One block You are working in the resource distribution team of your company. A One

Question
19
Max. score: 20.00
One block
You are working in the resource distribution team of your company. A One block is a block of data having exactly one resource which has value 1. You are given an array Arrcontaining N resource values.
What is the number of ways to divide the array into continuous blocks such that each block is One block.
Function description
Complete the function OneBlock() which takes aninteger N and an array Arr. This function takes the following 2 parameters and returns the required answer:
N: Represents the number of resources
Arr:Represents the value of resources
Input format for custom testing
Note: Use this input format if you are testing against custom input or writing code in a language where we dont provide boilerplate code
The first line contains an integer Ndenoting the number of resources.
The second line containsN space-separatedintegersdenoting the value of resources.
Output format
Printthe number of ways to divide the array into continuous blocks such that each block is One block.
Constraints
1
<=
<=
100
0
<=
<=
1
Sample input
3
010
Sample output
1
Explanation
Given
N =3
Arr =[0,1,0]
Approach
There is exactly one resource that has the value of 1. Hence, the number of ways is 1.
The following test cases are the actual test cases of this question that may be used to evaluate your submission.
Sample input 1
5
10101
Sample output 1
4
Sample input 2
10
0010001101
Sample output 2
8
Sample input 3
1
1
Sample output 3
1
Note:
Your code must be able to print the sample output from the provided sample input. However, your code is run against multiple hidden test cases. Therefore, your code must pass these hidden test cases to solve the problem statement.
Limits
Time Limit: 1.0 sec(s) for each input file
Memory Limit: 256 MB
Source Limit: 1024 KB
Scoring
Score is assigned if any testcase passes
Allowed Languages
Bash, C, C++14, C++17, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java 8, Java 14, JavaScript(Node.js), Julia, Kotlin, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, Python 3.8, Racket, Ruby, Rust, Scala, Swift, TypeScript, Visual Basic

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

Students also viewed these Databases questions