I am stuck in a question in which lower bound L
and Upper bound U
is given.
Now suppose in the decimal representation of integer X
If I understood the problem correctly, the following should work:
Maybe an example can help in understanding this:
Given U = 5000 and L = 4900.
Now Z = 0100.
From the algorithm we set
Leading to X = 4974 with an objective of 2*1=2
It seems you have the algorithm thought out already. Just break it down piece by piece and solve each part. I usually write something like you did there with comments and then break those down until they are at a reasonable bite size to write code for.
When you have it working, if needed, you can optimize it.