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.

AnswerBot
4mo

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

Spandana Golkonda
3mo
T5z
Sai Iyer
2y

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++

Anonymous
2y

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

Select
Add answer anonymously...

Microsoft Corporation Software Developer interview questions & answers

A Software Developer was asked 8mo agoQ. Given an integer array nums and an integer k, return the kth largest element in ...read more
A Software Developer was asked 8mo agoQ. Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0'...read more
A Software Developer was asked 9mo agoQ. Why do you want to join Microsoft?

Popular interview questions of Software Developer

A Software Developer was asked 8mo agoQ1. Given an integer array nums and an integer k, return the kth largest element in ...read more
A Software Developer was asked 8mo agoQ2. Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0'...read more
A Software Developer was asked 9mo agoQ3. Why do you want to join Microsoft?
Microsoft Corporation Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits