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

  • Home
  • SEARCH
  • 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 85555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:06:28+00:00 2026-05-10T22:06:28+00:00

I need a function count_permutations() that returns the number of permutations of a given

  • 0

I need a function count_permutations() that returns the number of permutations of a given range. Assuming that the range is allowed to be modified, and starts at the first permutation, I could naively implement this as repeated calls to next_permutation() as below:

template<class Ret, class Iter> Ret count_permutations(Iter first, Iter last) {     Ret ret = 0;     do {         ++ret;     } while (next_permutation(first, last));     return ret; } 

Is there a faster way that doesn’t require iterating through all the permutations to find the answer? It could still assume that the input can be modified, and starts in the first permutation, but obviously if it is possible to implement without those assumtions it’d be great too.

  • 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. 2026-05-10T22:06:29+00:00Added an answer on May 10, 2026 at 10:06 pm

    The number of permutations for a range where all the elements are unique is n! where n is the length of the range.

    If there are duplicate elements, you can use n!/(n_0!)…(n_m!) where n_0…n_m are the lengths of duplicate ranges.

    So for example [1,2,3] has 3! = 6 permutations while [1,2,2] has 3!/2! = 3 permutations.

    EDIT: A better example is [1,2,2,3,3,3] which has 6!/2!3! = 60 permutations.

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

Sidebar

Ask A Question

Stats

  • Questions 276k
  • Answers 276k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer How about this (you don't need the template parameter T,… May 13, 2026 at 2:52 pm
  • Editorial Team
    Editorial Team added an answer If the possible values of v_order_by are static, you can… May 13, 2026 at 2:52 pm
  • Editorial Team
    Editorial Team added an answer i am not sure but as far as i know… May 13, 2026 at 2:52 pm

Related Questions

After reading this question I started to wonder: is it possible to have a
I am trying to create a function which will give me alphabet position when
I'm quite new to subject of writting stored function for mySQL database, hence i'm
Assume I have an array of doubles that looks like the following: Array[10] =

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.