I think the point is that they do not wish to add a class or ID statically, but want some code to find the most deeply nested
<ul>(s). The example given is rather confusing, as it shows the desired result, rather than the HTML that is initially given.
One other point of small confusion is the request to add "CSS class" but what is shown is inline style, not class. Maybe the inline style was just shown to highlight in the example. In actual use, I'd recommend just styling in a CSS style sheet based on the most-deeply-nested class.
In any case, an ID would not do, since IDs must be unique, and there there may be more than one <ul> at the same nesting level. If done statically (or on server when HTML is created) would need to use a CSS class as the author has shown, rather than an ID.
This StackOverflow looks useful. It doesn't quite solve this particular problem, but can be used as part of a solution. Ignore the "click" callback part of this. This short solution can be used to determine the nesting level of any particular <ul>. You'll need an ID on the "root" element of the tree for use with parentsUntil().
One way for a complete solution would be to use a two-pass process and attach the nesting level to each <ul> using .data() on the first pass. At the same time, you can maintain a variable with the deepest level number encountered. On the second pass, you will go through again, find the element(s) where the .data() item value matches the deepest nesting level, and then add a CSS class to those.
Leaving this as an exercise for the author, as unsure if this is exactly what is wanted. But it might point in the right direction.