PROBLEM 5 (12 pts) - List of pairs of elements with given difference in a sorted list Write a function which receives as
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
PROBLEM 5 (12 pts) - List of pairs of elements with given difference in a sorted list Write a function which receives as
PROBLEM 5 (12 pts) - List of pairs of elements with given difference in a sorted list Write a function which receives as input a sorted list (smallest to largest) and the value of the difference and returns a list of pairs of numbers whose difference is equal to the given value. Your solution should be as efficient as possible. def listOfPairsWithGivenDifference (some SortedList, difference): Example: listOfPairsWithGivenDifference ([2,5,24,32,45,54,75],30) listOfPairsWithGivenDifference ([2,5,24,32,45,54,62],30) --> [(2,32), (24,54), (45,75)] --> [(2,32),(24,54),(32,62)]
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!