Here, I am providing my solution to the problem "**Get Storage**" with the intention to help you learn and understand Python 3 in a better way.

Please make use of my blog posts for learning purposes only and feel free to ask your questions in the comment box below in case of any doubt.

Click Here to check out all other HackerRank solutions.

Recommended Python Courses:

1. Udemy: Top Python Courses

2. Udemy: 2021 Complete Python Bootcamp From Zero to Hero in Python

3. Udemy: Learn Python Programming Masterclass

4. Coursera: Python for Everybody

5. LinkedIn: Become a Python Developer

6. edX: Programming for Everybody (Getting Started with Python)

7. edureka: Python Programming Certification Training

8. Eduonix: Mighty Python Bundle

## Python Problem Description:

There are a number of computers which are connected to each other. Each computer has a storage capacity which can be used to store data. When a computer is connected to another, they form a set of computers

and the storage capacity of the set is the sum of the storage capacities of the computers in the set.

You are given the set of connections between the computers by the arrays connections_from and connections_to (The connections are bi-directional). The initial storage capacities are denoted by

storage[storage[0],...,storage[connections_nodes-1]]. Also, you are given a threshold of storage capacity. After every connection, you are required to find the number of sets of computers which have storage capacity

less than or equal to threshold.

**Note:** Initially there are no connections between the computers and each computer can be considered as a set with 1 computer.

**For example**

- connections_nodes = 3. storage = {2, 3, 6}, connections_from = {0, 0, 2}, connections_to = {1, 2, 1}, threshold = 6.
- After 1st connection {0, 1}: {5, 6} (2 values are less than or equal to 6)
- After 2nd connection {0, 2}: {11} (no value is less than or equal to 6)
- After 3rd connection {2, 1}: {11} (no value is less than or equal to 6)

**Return an array containing the answer after each connection.**

## Function Description:

an integer denoting the number of computers*connections_nodes:*an array of integers denoting the ith connection*connections_from:*an array of integers denoting the ith connection*connections_to:*an array of integers denoting the initial storage capacities*storage:*an integer*threshold:*

## Constraints:

- 1 ≤ connections_nodes ≤ 105
- 1 ≤ connections_edges ≤ min( (connections_nodes) * (connections_nodes-1)/2, 105)
- 0 ≤ connections_fromi, connections_toi < connections_nodes
- 1 ≤ storage i ≤ 104
- 1 ≤ threshold ≤ 109
- The graph does not contain a self-loop or multiple edges between two nodes.

## Input Format For Testing:

- The first line contains 2 space-separated integers, connections_nodes and connections_edges, denoting the number of computers and number of connections respectively.
- Each line
of the connections_edges subsequent lines (where 0 ≤ i < connections_edges) contains 2 space-separated integers describing connections_from*i*and connections_to*i*.*i* - The next line contains an integer, connections_nodes, denoting the number of elements in storage.
- Each line
of the connections_nodes subsequent lines (where 0 ≤ i < connections_nodes) contains an integer storage*i*.*i* - The last line contains the integer threshold.

## Sample Case 0:

### Sample Input For Testing:

### Sample Output:

## Explanation:

- Initial storage capacities: {1, 2, 3, 4, 5}
- After 1st connection {0, 1}: {3, 3, 4, 5} (3 values are less than or equal to 4)
- After 2nd connection {1, 4}: {3, 4, 8} (2 value is less than or equal to 4)
- After 3rd connection {0, 4}: {3, 4, 8} (2 value is less than or equal to 4)

## Sample Case 1:

### Sample Input For Testing:

### Sample Output:

## Explanation:

- Initial storage capacities: {1, 2, 3}
- After 1st connection {0, 1}: {3, 3} (2 values are less than or equal to 4)
- After 2nd connection {1, 2}: {6} (no value is less than or equal to 4)

## Task Weightage:

## Note: You can choose any language for coding Java, c++, python, go.

Try to code on your local machine and final script update here.

## Python 3 Solution:

## Output:

### [Case-0] Output:

### [Case-1] Output:

**Click here**to see solutions for all

**Machine Learning**Coursera Assignments.

**Click here**to see more codes for

**Raspberry Pi 3**and similar Family.

**Click here**to see more codes for

**NodeMCU ESP8266**and similar Family.

**Click here**to see more codes for

**Arduino Mega (ATMega 2560)**and similar Family.

**-Akshay P Daga**