Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A subsequence of a number is a series of (not necessarily contiguous) digits of the number. For example, 12345 has subsequences that include 123, 234,
A subsequence of a number is a series of (not necessarily contiguous) digits of the number. For example, 12345 has subsequences that include 123, 234, 124, 245, etc. Your task is to get the maximum subsequence below a certain length.
def max_subseq(n, l): """ Return the maximum subsequence of length at most l that can be found in the given number n. For example, for n = 20125 and l = 3, we have that the subsequences are 2 0 1 2 5 20 21 22 25 01 02 05 12 15 25 201 202 205 212 215 225 012 015 025 125 and of these, the maxumum number is 225, so our answer is 225. >>> max_subseq(20125, 3) 225 >>> max_subseq(20125, 5) 20125 >>> max_subseq(20125, 6) # note that 20125 == 020125 20125 >>> max_subseq(12345, 3) 345 >>> max_subseq(12345, 0) # 0 is of length 0 0 >>> max_subseq(12345, 1) 5 """ Write the max_subseq function.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started