Contents

**Grid Connections Amazon OA 2023 Solution**

A supply chain manager at Amazon Logistics 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 i node.

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.

**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.

**SOLUTION**

**Program:** ** Grid Connections Solution** in Python

```
def gridOfNodes(self, intervals: list[list[int]]) -> int:
connections = 0
prevNodes = 1
# print(len(intervals[0]))
for i in range(len(intervals)):
currNodeCount = 0
for j in range(len(intervals[0])):
if(intervals[i][j] == 1):
currNodeCount+= 1
if i == 0:
prevNodes = currNodeCount
continue
elif currNodeCount >= 1:
connections += currNodeCount * prevNodes
prevNodes = currNodeCount
return connections
```

**Program:** ** Grid Connections Amazon OA Solution** in Python

```
import collections
class Solution:
def gridOfNodes(self, intervals: list[list[int]]) -> int:
connections = 0
prevNodes = intervals[0].count(1)
for interval in intervals[1:]:
currNodeCount = interval.count(1)
if currNodeCount >= 1:
connections += currNodeCount * prevNodes
prevNodes = currNodeCount
return connections
```

**Amazon OA 2023 Questions** **with Solution**

- Shopping Patterns Solution Amazon OA 2023
- Reorder Data in Log Files Solution Amazon OA 2023
- Top K Frequent Words Solution Amazon OA 2023
- Trees Height Solution Amazon OA SDE 2023
- Counting Binary Substrings Amazon OA 2023
- Shipment Imbalance Amazon OA 2023
- Max Profit Amazon OA 2023
- Find Lowest Price Amazon OA 2023
- Decode String Frequency Amazon OA 2023
- Simple Cipher Amazon OA 2023
- Valid Discount Coupons Amazon OA 2023 Solution
- Count Maximum Teams Amazon OA 2023
- Minimum Coin Flips Amazon OA 2023
- Max Average Stock Price Amazon OA 2023 Solution
- Robot Bounded In Circle Amazon OA 2023
- Shopping Options Amazon OA 2023 Solution
- Fill The Truck Maximum Units on a Truck Amazon OA Solution
- Maximize Score After N Operations Number Game Solution Amazon OA 2023
- Slowest Key Amazon OA 2023 Solution
- Five Star Seller Maximum Average Pass Ratio Amazon OA 2023
- Split String Into Unique Primes Amazon OA 2023 Solution
- Storage Optimization Amazon OA 2023 Solution
- Minimum Difficulty of a Job Schedule Amazon OA 2023 Solution
- Autoscale Policy Utilization Check Amazon OA 2023
- Optimal Utilization Solution Amazon OA 2023
- Merge Two Sorted Lists Solution Amazon OA 2023
- Two Sum Unique Pairs Solution Amazon OA 2023
- Amazon Music Pairs Amazon OA 2023 Solution
- Class Grouping Amazon OA 2023 Solution
- Find Max products Amazon OA 2023 Solution
- Get encrypted number Amazon OA 2023 Solution
- Find Total Imbalance Amazon OA 2023 Solution
- Find Total Power Amazon OA 2023 Solution