Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
C++ program to find perfect array of size n whose subarray is a good array
Suppose we have a number n. An array B is good if the sum of its elements is divisible by the length of this array. We can say an array A with n elements is perfect, if non-empty subarray of this array A is good and elements in A is in range 1 to 100. From the number n, we have to find an array A which is perfect.
So, if the input is like n = 4, then the output will be [7, 37, 79, 49], other answers are also possible.
Steps
To solve this, we will follow these steps −
for initialize i := 0, when iExample
Let us see the following implementation to get better understanding −
#includeusing namespace std; void solve(int n){ for(int i=0;i Input
4Output
1, 1, 1, 1,
Advertisements
