r/programmingchallenges • • Jul 02 '18

The Watermark Problem

http://ruslanledesma.com/2018/07/01/the-watermark-problem.html
3 Upvotes

7 comments sorted by

View all comments

Show parent comment

1

u/mr-rusof Jul 03 '18

Your proposed Java solution does not print the amount of water for the empty histogram. For input file "\n", expected output file is "0\n". Try inserting lines 20-50:

...
10:      Scanner s = new Scanner(sl.nextLine());
20:      if(!s.hasNextInt()) {
30:        System.out.println(0);
40:        continue;
50:      }  
60:      ArrayList<Integer> bar = new ArrayList<Integer>();
...

1

u/lrflew Jul 03 '18

That was it. I looked over the page again, and it doesn't seem to mention that an empty histogram is valid input. My intuition for this kind of thing is to consider empty lines as non-data, so it might help to make that explicit on at least the Book of Problems page.

One last comment, I see that it supports checking C, but not C++. It would be nice for it to support C++ as well (I'm not even sure who'd want to write a std-in parser in C if they could use C++ instead).

1

u/mr-rusof Jul 09 '18

Just deployed support for C++, check it out.