Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6204505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:06:18+00:00 2026-05-24T05:06:18+00:00

There is an array of integers, lets say 3,5,7,9. You are supposed to create

  • 0

There is an array of integers, lets say 3,5,7,9. You are supposed to create another array and populate it such that the second array’s 0th position should be a product of all numbers from the first array excluding the number at its 0th position, meaning it should be 5x7x9(excluding 3), number at the index 1 of the second array will be product of 3x7x9 (excluding 5).

The first answer that came up to my mind was having 2 for loops which will lead to a time complexity of O(n2). Later I figured this:

Multiplying all the numbers in the first array(3x5x7x9), and while populating the second array I will divide this product by the number at that position. divide by 3 if I am populating the 0th position, divide by 5 if I am populating the 1st position and so on. This would bring down the complexity from O(n2) to probably O(2n).

But the interviewer says division is not allowed. I could not think of anything else but storing the different possible multiples in some kind of a data structure and using it while populating. I gave up, but when asked for the answer he said he would maintain 2 arrays of forward and backward multiples. When asked about the space complexity issue of the solution, he said it could be optimized.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:06:18+00:00Added an answer on May 24, 2026 at 5:06 am

    I’m not sure if the question is about the space or about the solution itself. Since everyone has been providing solutions it leads me to think they didn’t understand the interviewer’s solution, so here is an explanation:

    We maintain two arrays. The first, the running product of the numbers of the original array. So the element at place i will be the product of the first i elements in the original array (no latex, but the ith entry has value it’s pi{j=0 to i} j). And the second array is simply the reverse direction of that, so the ith entry will have value: pi{j=N-i to N} j.

    To construct the final array required, we simply run along each of our two arrays and multiply entries. So the ith value in the final array, will be the product of all the entries, which is the product of 0 to i-1 times the product of i+1 to N, which is the product of the first array’s i-1 entry and the second array’s i+1 entry.

    Total time and space O(n)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have the following two PHP arrays that contain integers: $foo =
I know that to create array with integers in Object-c they have to be
Let's say I have an array of n integers and I am supposed to
Say I have a dynamic array like: int* integers = new int[100]; Is there
Scenario: If there is an array of integers and I want to get array
Is there a better way to shell sort using C#? // array of integers
What is the appropriate function that shows how many are there in an array?
So basically I got string array, lets say a[i][b]; so the code looks something
Lets say you have various objects of arbitrary type that you would like to
This is an interview question There is an array of integers. The elements in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.