Files
freecodecamp--freecodecamp/curriculum/challenges/english/blocks/daily-coding-challenges-python/6a0dcd03ee4e68698080ef68.md
T
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

2.2 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6a0dcd03ee4e68698080ef68 Challenge 304: Itinerary Arrangements 29 challenge-304

--description--

Given an array of at least two optional stops for a day trip, return the number of valid itinerary arrangements.

The itinerary always includes "breakfast", "lunch", and "dinner", these will not be passed in as arguments. The optional stops can be placed anywhere in the itinerary, subject to the following rules:

  • "breakfast" is always first, with at least one stop before "lunch".
  • "lunch" must appear before "dinner", with at least one stop in between.
  • At most, one optional stop may appear after "dinner".

Return the number of valid arrangements.

--hints--

get_itinerary_count(["library", "park"]) should return 2.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_itinerary_count(["library", "park"]), 2)`)
}})

get_itinerary_count(["library", "park", "arcade"]) should return 18.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_itinerary_count(["library", "park", "arcade"]), 18)`)
}})

get_itinerary_count(["library", "park", "arcade", "store"]) should return 120.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_itinerary_count(["library", "park", "arcade", "store"]), 120)`)
}})

get_itinerary_count(["library", "park", "arcade", "store", "cafe"]) should return 840.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_itinerary_count(["library", "park", "arcade", "store", "cafe"]), 840)`)
}})

get_itinerary_count(["library", "park", "arcade", "store", "cafe", "market", "museum"]) should return 55440.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_itinerary_count(["library", "park", "arcade", "store", "cafe", "market", "museum"]), 55440)`)
}})

--seed--

--seed-contents--

def get_itinerary_count(stops):

    return stops

--solutions--

from math import factorial

def get_itinerary_count(stops):
    n = len(stops)
    return (2 * n - 3) * factorial(n)