Grid Connections Amazon OA Solution
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.
grid: the nodes grid
the total number of connections
Input: 1grid = [[1, 1, 1], [0, 1, 0], [0, 0, 0], [1, 1, 0]]
There are a total of 3+2=5 connections.
Program: Grid Connections Amazon OA Solution in Python
def gridOfNodes(self, intervals: list[list[int]]) -> int: connections = 0 prevNodes = 1 # print(len(intervals)) for i in range(len(intervals)): currNodeCount = 0 for j in range(len(intervals)): if(intervals[i][j] == 1): currNodeCount+= 1 if i == 0: prevNodes = currNodeCount continue elif currNodeCount >= 1: connections += currNodeCount * prevNodes prevNodes = currNodeCount return connections
Second Solution Program: Grid Connections Amazon OA Solution in Python
import collections class Solution: def gridOfNodes(self, intervals: list[list[int]]) -> int: connections = 0 prevNodes = intervals.count(1) for interval in intervals[1:]: currNodeCount = interval.count(1) if currNodeCount >= 1: connections += currNodeCount * prevNodes prevNodes = currNodeCount return connections
Amazon Online Assessment Questions:
- Robot Bounded in Box
- Number Game
- Find All Combination of Numbers Sum to Target / Shopping Options
- Fill the Truck
- Music Pairs
- Slowest key
- Five Star Seller
- Split String Into Unique Primes
- Storage Optimization
- Minimum Difficulty of a Job Schedule
- Autoscale Policy, Utilization Check
- Optimal Utilization
- Merge Two Sorted Lists
- Two Sum Unique Pairs
- Shopping Patterns
- Reorder Data in Log Files
- Top K Frequent Words
- Trees Height
- Counting Binary Substrings Amazon OA Solution
- Grid Connections Amazon OA Solution
- Shipment Imbalance Amazon OA Solution
- Max Profit Amazon OA Solution
- Find Lowest Price Amazon OA Solution
- Simple Cipher Amazon OA Solution
- Decode String Frequency Amazon OA Solution
- Valid Discount Coupons Amazon OA Solution
- Count Maximum Teams Amazon OA Solution
- Minimum Coin Flips Amazon OA Solution
- Stock Price Amazon OA Solution