Question
Hi, How can I print out the results for this Python Class ? Given an array A of sorted integers and another non negative integer
Hi,
How can I print out the results for this Python Class ?
Given an array A of sorted integers and another non negative integer k, find if there exists 2 indices i and j such that A[i] - A[j] = k, i != j.
Example:
Input :
A : [1 3 5] k : 4
Output : YES
as 5 - 1 = 4
Return 0 / 1 ( 0 for false, 1 for true ) for this problem
Try doing this in less than linear space complexity.
class Solution: # @param A : list of integers # @param B : integer # @return an integer def diffPossible(self, A, B): dif = 0 for i in xrange(0, len(A) - 1): for j in xrange(i + 1, len(A)): dif = A[j] - A[i] if dif == B: return 1 if dif > B: break return 0
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