Efficient Method to Find the Lexographic Min of a Range of Integers
Given two positive integers, say M and N, with M < N, what is the most efficient algorithm to find the minimum in lexicographical order of the strings of the integers from M to N represented in base ten ASCII without leading zeros? For example, for [200, 10890], the answer is '1000', 开发者_运维技巧for [298, 900], the answer is '298'.
I think you're probably right in your intuition that there's a constant-time algorithm for this. You'd first find the smallest first digit, then the smallest second digit, etc.
精彩评论