Implement array diff algorithm