I can imagine people using nested for loops to solve this problem, where in the nested for loop you build a string and ensure the last n – m characters are a ‘#’. Another solution which I opted for as it seemed more intuitive was simply to use a buffer to store the last ‘#’, and then replace the null character at the index before hand with the next ‘#’. This uses a buffer of N space, and so if N is particularly large may cause runtime problems. However it requires only O(N) operations to complete.