# Amazon Online Assessment 2021 (OA) - Grid Connections

A supply chain manager at Amazon Logisitcs wants to determine the number of connections between warehouses, represented as nodes on a grid. A grid with m rows and n columns is used to form a cluster of nodes. If a point in the grid has a value of 1, then it represents a node.

Each node in the cluster has a level associated with it. A node located in the ith row of the grid is a level inode.

Here are the rules for creating a cluster:

• Every node at a level connects to the next level that contains at least 1 node (i.e., every node at level i connects to all the nodes at level k where k > i and k is the first level after level i than contains at least one note).
• When i reaches the last level in the grid, no more connections are possible.

Given such a grid, please help the supply chain manager by finding the number of connections present in the cluster.

Relevant Amazon OA Problems:

### Input

• `grid`: the nodes grid

### Output

the total number of connections

### Examples

#### Example 1:

Input:

``1grid = [[1, 1, 1], [0, 1, 0], [0, 0, 0], [1, 1, 0]]``

Output: `5`

Explanation:

There are a total of 3+2=5 connections.

## Title

### Script

Lorem Ipsum is simply dummy text of the printing and typesetting industry. `Lorem` `Ipsum` has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Contrary to popular belief, `Lorem` `Ipsum` is not simply random text.

``````1  >>> a = [1, 2, 3]
2  >>> a[-1]
3  3``````