Now, this is a tricky prompt. Now, looking at what the algorithm wrote (when you overlook the spacing difficulties), it…