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.
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 Microsoft Corporation Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Microsoft Corporation Software Developer
Reviews
Interviews
Salaries
Users/Month