Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Two integers A and B are given. We are interested in positions at which the decimal representation of A occurs as a substring in
Two integers A and B are given. We are interested in positions at which the decimal representation of A occurs as a substring in the decimal representation of B (counting from 0). For example: 53 occurs in 1953786 at position 2. 78 occurs in 195378678 at positions 4 and 7. 57 does not occur in 153786. Decimal representations are assumed to be big-endian and without leading zeros (the only exception being the number 0, whose decimal representation is "0"). Write a function def solution (A, B) that, given two integers A and B, returns the leftmost position at which A occurs in B. The function should return -1 if A does not occur in B. For example, given A = 53 and B = 1953786, the function should return 2, as explained above. Assume that: A and B are integers within the range [0..999,999,999]. In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment.
Step by Step Solution
★★★★★
3.32 Rating (161 Votes )
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