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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:08:12+00:00 2026-05-26T20:08:12+00:00

We have a group of objects, let’s call them Players. We can traverse through

  • 0

We have a group of objects, let’s call them Players. We can traverse through this group only with random order, e.g. there is no such thing as Players[0].

Each Player has a unique ID, with ID < len(Players). Player’s can be added and removed to the group. When a Player gets removed it will free his ID, and if a Player gets added it will acquire an ID.

If we want to add a new Player to Players we have to generate a new unique ID. What is the fastest way to generate such ID in O(1) space?

  • 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-26T20:08:13+00:00Added an answer on May 26, 2026 at 8:08 pm

    O(n log n) is possible with binary search. Start with a = 0 and b = n. The invariant is that there exists a free id in the interval [a, b). Repeat the following until b – a = 1: let m = a + floor((b – a) / 2), count the number of ids in [a, m) and in [m, b). If [a, m) has fewer than m – a ids, then set b = m. Otherwise, set a = m.

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

Sidebar

Related Questions

I have two objects, let's call them Input and Output Input has properties Input_ID
Let's say I have the following objects: Fxy.commands={ group:{ add:function(msg){ So, of course, Fxy.commands.group.add('something')
In my app, I have a group of 3d objects and they're exposed to
I have a method to return a group of objects as a generic list
I have a group of checkboxes that I only want to allow a set
Let's say I have a list that looks like this: <ul> <li id=q></li> <li
I'm building an app where you can search for objects in a database (let's
Here's the abstract situation: I have CoreData objects 'car' and 'review'.'review' can be 'good','bad'
Let's say I have the following objects: squirrel_table - name - country_of_origin - id
Let's say I have the results of a call to Select-String in a variable

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.