static List<List<Integer>> getSequences(TreeNode root){
        List<List<Integer>> lists= new ArrayList<>();
        if(root==null)return lists;
        List<Integer> list=new ArrayList<>();
        list.add(root.val);
        lists.add(list);

        Queue<TreeNode> levelNodes= new LinkedList<>();
        levelNodes.add(root);
        int level=1;

        while (!levelNodes.isEmpty()){
            TreeNode node=levelNodes.remove();
            level--;
            if(node.left!=null)levelNodes.add(node.left);
            if(node.right!=null)levelNodes.add(node.right);
            if(level==0 && !levelNodes.isEmpty()){
                List<List<Integer>> perms=new ArrayList<>();
                getPermutations(new ArrayList<>(levelNodes), perms, 0);

                List<List<Integer>> lists2=new ArrayList<>();
                for (List<Integer> integers : lists) {
                    for (List<Integer> perm : perms) {
                        List<Integer> newLevel= new ArrayList<>();
                        newLevel.addAll(integers);
                        newLevel.addAll(perm);
                        lists2.add(newLevel);
                    }
                }
                lists=lists2;
            }
        }
        return lists;
    }
Solution is simple. Do level order traversal in binary search tree, and for each level nodes get all
possible permutations to make new lists
src/problems/medium/BSTSequences.java