Amazon Coding Question – Solved

4 Live
The Amazon warehouse receives a multitude of packages every day, each assigned a unique identifier from 1 to n. The warehouse manager must sort the packages, not by their identifiers, but rather through a specific process defined by a permutation sorterOrder that ensures optimal processing. Initially, the number of sorted packages, sortedCount, is zero. In each operation, the manager sifts through the packages from left to right. If the current package's identifier aligns with the next one to be sorted (i.e., sorterOrder[i] = sortedCount + 1), the manager sorts it and increments sortedCount by one. If the current package is not next in the sorting sequence, the manager overlooks it. Determine the number of operations required by the manager to sort all the packages. One operation indicates a complete check from the first package to the last. Note: A permutation is a sequence consisting of integers from 1 to n, of length n, containing each integer exactly once. For example, [1, 3, 2] is a permutation, while [1, 2, 1] is not. Example 1: n = 5 sorterOrder = [5, 3, 4, 1, 2] Initially sortedCount = 0. In the first operation, the manager does the following:

Asked in: Amazon

Image of the Question

Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| Given an n x m grid, where rows are numbered from 7 to n and columns from 1 to … |
| There are 'N' coders standing in a line, where i denotes the ith position of a … |
| A birthday party was attended by N number of kids, and each kid was given a uni… |
| Given a matrix of size m * n, where m denotes the number of rows (starting with… |
| A traveler is traveling from the city of Zeta to Omega. He starts with X amount… |
| As an operations engineer at Amazon, you are responsible for organizing the dis… |