arr = [] diff = [] for i in range(n-1): diff.append(arr[i+1]-arr[i]) code example Example: if(arr[i]==k) return arr[i]; if(arr[i]==k){ return arr[i]; }