
Asked in Microsoft Corporation
Buses Origin Problem Statement
You have been provided with an array where each element specifies the number of buses that can be boarded at each respective bus stop. Buses will only stop at locations that are multiples of the bus stop they originate from. Your task is to determine how many buses originate from each bus stop in the range from 1 to N.
Input:
The first input line contains the integer 'T', the number of test cases to process.
For each test case, there are two lines of input:
The first line contains the integer 'N', the length of the array.
The second line contains 'N' space-separated integers representing the number of buses that can be boarded at each bus stop.
Output:
For each test case, output 'N' integers indicating the number of buses originating from each bus stop from 1 to N.
Example:
If 'N' = 4 and the array is: [1, 3, 4, 3]
The result would be: [1, 2, 3, 0]
Constraints:
- 1 ≤ T ≤ 50
- 1 ≤ N ≤ 104
- 1 ≤ Ai ≤ 106
Note:
The bus stops and the array use 1-based indexing.

Given an array representing number of buses at each bus stop, determine how many buses originate from each stop.
Iterate through the array and for each element, increment the count of buses originating...read more
vector<int> countBuses(vector<int> arr, int n){ arr.insert(arr.begin(), -1); for(int i=1; i<=n; i++) for(int j=i*2; j<=n; j=j+i) arr[j]=arr[j]-arr[i]; arr.erase(arr.begin()); return arr; }
This is C++
The language is c++
vector<int> countBuses(vector<int> arr, int n){ arr.insert(arr.begin(), -1); for(int i=1; i<=n; i++) for(int j=i*2; j<=n; j=j+i) arr[j]=arr[j]-arr[i]; arr.erase(arr.begin()); retur...read more
Top Software Developer Interview Questions Asked at Microsoft Corporation
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for Microsoft Corporation Software Developer


Reviews
Interviews
Salaries
Users

