Question: I started using atom as my editor for learning Javascript. I've followed a bunch of tutorials online and while my code looks exactly like it does in the tuts, for some reason I'm missing the Javascript behavior. Here is a simple example of my code that simply won't run out of atom, notepadd++ or notepad. In atom I use the atom-live-server, in notepadd i basiclaly open it on local host. ANyoe have any idea?

```
<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <title>Document</title>
</head>
<body>
   <form name="login">
      <input type="text" placeholder="Username" name="UserID"><br>
      <input type="text" placeholder="Password" name="Pass"><br>
      <input type ="button" onclick="check(this.form)" value="Login"/>
   </form>

   <script type="text/javascript">
      function check(form){
         if(form.userId.value=="" || form.pass.value==""){
            alert("BLAHBLAHBLAH")
         }
      }
   </script>
</body>
</html>

```

Answer: 
As suggested by @qwertyman in the comments 

1. remove all invalid edges i.e edges whose difference is greater than 1
2. Now we have a forest, for each forest calculate the diameter as it is given in @Filip Kočica solution
3. The answer would be the max diameter out of all forests
For each subtree, you can calculate the longest increasing path down from the subtree root, the longest decreasing path down, and the longest internal path consisting of the increasing and decreasing paths down from the same node anywhere in the subtree.

It's easy to calculate these for a node if you already have them for all of its children, so you can do it as part of any postorder traversal.

The answer is the longest internal path within the whole tree.