Okay, so today I decided to tackle this “1861 numbers” thing. I’d seen it pop up a few times, and figured, why not? Let’s see what this is all about.
First, I needed to figure out what exactly I was dealing with. Was it a coding challenge? Some kind of math puzzle? I did some digging, and it turns out it’s a LeetCode problem. Classic. I always get sucked into these.
So I opened up LeetCode and found the problem. Basically, you’re given a string of digits, and you have to find all the possible numbers you can make by rearranging them, and also the largest number Smaller than the orginal number.

My initial thought was, “Okay, permutations. I can do that.” I’ve done permutation problems before, It should not that * the problem needs the largest number Smaller than the orginal number.I’m stucked.
I started by writing a simple function to generate all the permutations of the * Find a way to compare.
I used the compare way ,and try catch one by one .It must be stupid but I did not find a better solution.
My (Messy) Process
- Read the problem description (multiple times, because…reading is hard).
- Wrote some code to generate permutations.
- Compare the orignal number to the generated number,looking for the largest and smaller one.
- Ran the code, and…it worked. I’ll take it.
I’m not gonna lie, it took a bit longer than I expected. The compare part was a little more annoying. But hey, I got there in the end. Another problem solved, another small victory. Now, onto the next challenge…