Write a function which accepts a string consisting only of A, B, X and Y, and returns a maximum number of possible pairwise connection that can be made.
Here's the catch -- you need to follow the rules below:
- You can connect A with B or B with A or X with Y or Y with X.
- Each letter can participate in such connection only once.
- Connections must all be done in the same direction.
- Connections must not intersect.
B X A B A Y B A | |_| | |_| |_______|
No matter how you connect A to B and X to Y (without intersecting), you will only be able to make three connections in this example, so the answer for
This challenge comes from smiks on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email firstname.lastname@example.org with your suggestions!