Sainsbury’s interview question

typical leetcode, hackerrank medium level DS questions