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 6028259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:42:44+00:00 2026-05-23T04:42:44+00:00

We have an array A of integers of size N. Given another array B

  • 0

We have an array A of integers of size N. Given another array B which contains indices, where size of B <= N and 0<=B[i]<=N-1.

Now we have to remove all elements from array A at position B[i].

So with deletion we mean we are also shifting elements in array A.

Can someone help me in reaching to O(n) solution for this problem? And possibly O(1) space.

The first solution that comes to my mind is, traversing the array B and deleting elements in A sequentially( including shifting) but it is O(n^2).

  • 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-23T04:42:45+00:00Added an answer on May 23, 2026 at 4:42 am

    Similar to iliaden’s solution except you could do the removing of deleted elements in place.

    int[] a = 
    int[] b = 
    int nullValue = 
    for(int i: b) a[i] = nullValue;
    int j=0;
    for(int i=0; i < a.length; i++) {
        if(a[i] != nullValue)
           a[j++] = a[i];
    }
    // to clear the rest of the array, if required.
    for(;j<a.length;j++)
       a[j] = nullValue;
    

    note: a won’t be shorter, but it avoid creating any more space. ‘j’ will have the number of valid entries in a

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

Sidebar

Related Questions

I have a dynamically created array of integers. Now I have to remove all
I have an array of integers which represent a RGB image and would like
I have an array of integers like these; dim x as integer()={10,9,4,7,6,8,3}. Now I
I have an array with integers of values from 0 to 100. I wish
You are given two sorted integer arrays, which have some common integers. Any common
Say you need to have a list/array of integers which you need iterate frequently,
You are given an array of integers. You have to output the largest range
I have following code which should print array of 3072 integers: for(int q=0; q
Say I have an array of n integers, m , each chosen randomly from
I have an array of integers: int[] number = new int[] { 2,3,6,7 };

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.