#59 How long is the cable?


The goal is to calculate the length of a cable.


The cable will be symbolized with a combination of the following characters: -, _, =.


Each character has a different length: - is of length 1, _ of length 2 and = of length 3.


Sometimes the cable is making a loop. This will be symbolized with brackets.


When you have reached a closing bracket ), you have to go back to the corresponding opening bracket and count the length again -> this represents a loop.


For example:


Cable.calculateLength("----"); // => 4

Cable.calculateLength("_(-_)"); // => 8 --> _-_-_

Cable.calculateLength("_(-(_))="); // => 15 --> _(-__)= --> _-__-__=

If a cable is broken, meaning number of ( is not equal to number of ), you must throw a BracketException of type RuntimeException that you must implement yourself.


If the cable has a node, meaning a different character is detected on the input string, throw a NodeException of type RuntimeException (implement it as well)


If a cable is both broken and contains nodes then it should throw the exception that can be first detected and confirmed.


Good luck and keep an eye on the performance of your code - suboptimal solutions may time out in the Submit tests ;)



#23 Prime Streaming


Create an endless stream of prime numbers - a bit like IntStream.of(2,3,5,7,11,13,17), but infinite. The stream must be able to produce 50 million primes in a few seconds.


당당하게 도전하고 ,당당하게 망했다 3시간동안 고민해봤는데 못풀겠다.

현재 레벨보다 높은 단계라 솔루션도 못본다. 포기하고 다른문제 풀어서 올릴까하다가 

들인시간이 아까워서 주말에 다시 풀어보려고 올림



+ Recent posts