After solving problems like that for years, eventually almost anyone will develop such an ability, like one also would in regards to DB schema design, system design and picking architectures/design patterns.
The problem is that the majority of people simply don't spend time on issues like that, either in their day jobs or weekends/evenings. The closest you can get to things like that if you work in pretty boring domains, is having to pick between a Set or a Map for some data structure in the app. Or avoiding things like N+1 issues which have relatively little to do with algorithms and more in regards to how frameworks implement things.
The problem is that the majority of people simply don't spend time on issues like that, either in their day jobs or weekends/evenings. The closest you can get to things like that if you work in pretty boring domains, is having to pick between a Set or a Map for some data structure in the app. Or avoiding things like N+1 issues which have relatively little to do with algorithms and more in regards to how frameworks implement things.