First Odd Number in Alphabetical Ordering

Brain Teaser · Hard · Free problem

Every integer from

$ to
0^{10}$ (ten billion) is written out as an English word with all spaces and hyphens removed. For example, $7611$ becomes "seventhousandsixhundredeleven". These ten billion strings are then sorted in strict alphabetical order.

What is the first odd number that appears in this sorted list?

Hints

  1. The digit words in alphabetical order start: eight, five, four, nine, one, ... So the answer begins with "eight billion." What comes next alphabetically?
  2. At each digit group (millions, thousands, hundreds), greedily pick the alphabetically earliest continuation. Notice that "eighteen" beats "eighthundred" (because 'e' < 'h'), and "eighthundred" beats "eighty" (because 'h' < 'y'). All of these give even numbers, so you must keep going.
  3. Parity depends only on the last digit. In the ones/tens slot, trace the "eighty-" family: "eightyeight" (88, even) sorts before "eightyfive" (85, odd) because 'e' < 'f'. So $85$ is the first odd ending, giving $8{,}018{,}018{,}885$.

Worked Solution

How to Think About It: You are searching a giant alphabetically sorted list of number-words for the first odd entry. The trick is that alphabetical order is determined character by character, so the problem reduces to a greedy trie traversal: at each branching point, pick the alphabetically earliest continuation, and find the first path that yields an odd number. The critical observation is that parity depends only on the last digit, so every digit-group choice above the units level is free -- you just pick whichever is alphabetically first. The only place you need to deviate from the absolute greedy path is in the final few digits, where you need the result to be odd.

Quick Estimate: The digit words in alphabetical order are: eight, five, four, nine, one, seven, six, three, two. "Eight" dominates the front of the alphabet, and both $8$ and

8$ are even. The alphabetically first odd single-digit word is "five" (5). So the answer will be some number built from "eight" and "eighteen" at every level, with "eighty-five" (85) wedged into the units slot. That points toward something like $8{,}018{,}018{,}885$.

Approach: Trace through the alphabetical trie level by level -- billions, then millions, then thousands, then hundreds/tens/ones -- always picking the alphabetically earliest branch, and identify where the first odd number appears.

Formal Solution:

*Step 1 -- Billions digit.* The number is in the range

$ to
0^{10}$. Each number-word starts with a digit-word. Alphabetically, the digit words rank: eight < five < four < nine < one < seven < six < three < two. So the leading block is "eightbillion" and the number starts with $8{,}000{,}000{,}000$.

*Step 2 -- The remainder.* Write the number as $8{,}000{,}000{,}000 + R$ where $0 \le R \le 999{,}999{,}999$. The full word is "eightbillion" + word($R$). We need the alphabetically first word($R$) such that $R$ is odd.

*Step 3 -- Greedy descent through $R$.* Within $R$, the word is built from standard English groupings (millions, thousands, hundreds, tens, ones). After "eightbillion", we append word($R$) and sort character by character. Trace the alphabetically first values of $R$:

  • $R = 0$: no suffix, number is $8{,}000{,}000{,}000$ -- even
  • $R = 8$: "eight" -- even
  • $R = 18$: "eighteen" -- even

After "eighteen", the next continuations starting with "eighteen..." are "eighteenmillion" and "eighteenthousand" (note:

{,}800$ is "onethousandeighthundred", NOT "eighteenhundred", so there is no "eighteenhundred" branch). Comparing: 'm' < 't', so "eighteenmillion" sorts first.

  • $R = 18{,}000{,}000$: "eighteenmillion" -- even

*Step 4 -- Within the

8$ million block.* The suffix after "eighteenmillion" is a number $S$ from $0$ to $999{,}999$. Same greedy logic:

  • $S = 0$: $R = 18{,}000{,}000$ -- even
  • $S = 8$: "eight" -- even
  • $S = 18$: "eighteen" -- even
  • $S = 18{,}000$+: "eighteenthousand..." (again, 'm' < 't' doesn't apply here since there's no millions group in $0$-$999{,}999$; within this range "eighteenthousand" is the only "eighteen" extension)
  • $S = 18{,}000$: "eighteenthousand" -- even

*Step 5 -- Within the

8$ thousand block.* The suffix after "eighteenthousand" is $T$ from $0$ to $999$. Same logic:

  • $T = 0$: $S = 18{,}000$ -- even
  • $T = 8$: "eight" -- even
  • $T = 18$: "eighteen" -- even
  • $T = 800$+: "eighthundred..." (here there is no "eighteenthousand" or "eighteenmillion" available in
    $-$999$, so after "eighteen" we compare: 'e' in "eighteen" vs 'h' in "eighthundred" vs 'y' in "eighty" -- since 'e' < 'h' < 'y', "eighteen" comes first, then "eighthundred", then "eighty")
  • $T = 800$: "eighthundred" -- even

*Step 6 -- Within the hundreds.* The suffix after "eighthundred" is $U$ from $0$ to $99$:

  • $U = 0$: $T = 800$ -- even
  • $U = 8$: "eight", $T = 808$ -- even
  • $U = 18$: "eighteen", $T = 818$ -- even
  • $U = 80$: "eighty", $T = 880$ -- even
  • $U = 88$: "eightyeight", $T = 888$ -- even ("eightyeight" < "eightyfive" because 'e' < 'f')
  • $U = 85$: "eightyfive", $T = 885$ -- ODD!

*Step 7 -- Assemble the answer.*

$R = 18{,}000{,}000 + 18{,}000 + 800 + 85 = 18{,}018{,}885$

$\text{Answer} = 8{,}000{,}000{,}000 + 18{,}018{,}885 = 8{,}018{,}018{,}885$

Verify the word: "eightbillioneighteenmillioneighteenthousandeighthundredeightyfive." Every prefix of this string is alphabetically minimal, and $8{,}018{,}018{,}885$ is indeed odd (ends in $5$).

Answer: The first odd number in alphabetical order is $8{,}018{,}018{,}885$.

Intuition

This problem is a pure exercise in systematic greedy search over a trie of English number words. The key insight is that alphabetical ordering is determined character by character, so the "eight" family dominates the front of the list -- and unfortunately, 8 and 18 are both even. At every digit group (billions, millions, thousands, hundreds), the alphabetically optimal choice is an "eight" or "eighteen" variant, all of which are even. You can only escape this trap in the last two digits, where "eightyfive" (85) is the first odd number reachable in the "eighty-" branch. The self-similar structure is striking: the pattern "eighteen" repeats at the million, thousand, and hundred levels, producing the memorable answer $8{,}018{,}018{,}885$.

Problems like this test your ability to be methodical under pressure. The temptation is to guess and check, but the correct approach is to define a clear ordering rule (character-by-character comparison) and trace it systematically. This is the same skill you need when debugging edge cases in sorting algorithms or verifying that a comparator is well-defined -- slow down, define the rule precisely, and follow it.

Open the full interactive solver →