Well this is awkward. I created this question using a guest account and thought that I could have it registered using the email link I received. Now that I have registered it, I cannot seem to be able to upvote or comment on the answers. And this new account seems to be a completely different after registration, so I can't select an answer as a solution.
Anyway, I have been successful thanks to your answers.
The solution posted by @Robin Betts does the job. However, I didn't need the second method for a cuboid. I did it with the first one by passing the length/breadth/height as different parameters. I used vertices=(length+1), but I think length=(vertices-1) would be more intuitive.

The solution posted by @Chris has gaps between the cubes, which I believe can be fixed by the Resample Curve node.
Thank you all for helping me out.