Problem statement:
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
as5 - 1 = 4
Return
0 / 1
( 0 for false, 1 for true ) for this problem
Try doing this in less than linear space complexity.
First practice: The solution is not optimized for the time. Almost there.
https://gist.github.com/jianminchen/decb1042a4e8e66c50be2c80c70f063a
Second practice: The solution works
https://gist.github.com/jianminchen/f24bc4f8561f29ef5a98d8bd3460d8dd
Study the solution provided by code lab:
https://gist.github.com/jianminchen/e4906acce9c763626453adb182ee3b03
No comments:
Post a Comment