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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:20:50+00:00 2026-06-04T14:20:50+00:00

I was asked this today and i know the answer is damn sure simple

  • 0

I was asked this today and i know the answer is damn sure simple but he kept me the twist to the last.

Question

Write a program to remove even numbers stored in ArrayList containing 1 - 100.

I just said wow

Here you go this is how i have implemented it.

ArrayList source = new ArrayList(100);
for (int i = 1; i < 100; i++)
{
    source.Add(i);
}


for (int i = 0; i < source.Count; i++)
{
    if (Convert.ToInt32(source[i]) % 2 ==0)
    {
        source.RemoveAt(i);
    }
}

//source contains only Odd elements

The twist

He asked me what is the computational complexity of this give him a equation. I just did and said this is Linear directly proportional to N (Input).

he said : hmmm.. so that means i need to wait longer to get results when the input size increases am i right? Yes sirr you are

Tune it for me, make it Log(N) try as much as you can he said. I failed miserably in this part.

  • Hence come here for the right logic, answer or algorithm to do this.

note: He wanted no Linq, No extra bells and whistles. Just plain loops or other logic to do it

  • 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-06-04T14:20:51+00:00Added an answer on June 4, 2026 at 2:20 pm

    Let’s think it this way:

    The number of delete actions you are doing is, forcely, the half of array lenght (if the elements are stored in array). So the complexity is at least O(N) .

    The question you received let me suppose that your professor wanted you to reason about different ways of storing the numbers.

    Usually when you have log complexity you are working with different structures, like graphs or trees.

    The only way I can think of having logartmic complexity is having the numbers stored in a tree (ordered tree, b-tree… we colud elaborate on this), but it is actually out of the constraints of your exam (sotring numbers in array).

    Does it make sense to you?

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

Sidebar

Related Questions

I know I have asked this question in a different manner earlier today but
I have asked this question today already but this time I want to know
I asked another version of this question on the gamedev.SE site earlier today but
I have asked this question earlier today but I didn't provide enough information and
I have been asked this question today. When debugging, there is an error. But
OK, I asked this question earlier today How do I write a scope to
I'm almost sure this question has been asked before, but for the love of
I know this is probably simple and has probably been asked before, but I'm
I know this question has been asked 100x but I can't seem to find
I was asked this question in an interview today, and didn't know how to

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.