Need help with Trie insertions, I am currently working on a DSA specialization on Coursera, Strings course

I am trying the insertion operation in a Trie and a read operation for the below implementation I am having trouble with insertion.

import java.util.*; class node{ public int val; public node ptrs[]; node(){     this.val =0;     ptrs = new node[26];     for (node ptr : ptrs) {         ptr = null;     }   }     } class Tree{ public node root = new node(); public int pass =0; void insert(String s) {     node trv = root;     for (int i = 0; i < s.length(); i++) {         if (trv.ptrs[s.charAt(i) - 'A'] == null) {             trv.ptrs[s.charAt(i) - 'A'] = new node();             trv.val = ++pass;           //  System.out.println(s.charAt(i)+" val : "+trv.val);         }          trv = trv.ptrs[s.charAt(i) - 'A'];     } } private void visit(node trv){     for(int i =0;i<26;i++){         if(trv.ptrs[i]!=null){             System.out.println((char)(i+'A')+" : "+trv.val);             visit(trv.ptrs[i]);         }     } } void call(){     this.visit(root);  }  } public class trie {   public static void main(String[] args) {     Scanner sc = new Scanner(System.in);     int n = sc.nextInt();     Tree t = new Tree();     while (n-- > 0) {         String s = sc.next();         t.insert(s);     }     t.call();     sc.close();  } } 

my output :

3 ATAGA ATC GAT A : 7 T : 2 A : 6 G : 4 A : 5 C : 6 G : 7 A : 8 T : 9 

expected output :

3 ATAGA ATC GAT A : 1 T : 2 A : 3 G : 4 A : 5 C : 6 G : 7 A : 8 T : 9 

Mathematicians and Online Courses (e.g. MOOCs, Coursera, EdX, etc.)

What are the experiences of professional mathematicians in learning new things from MOOCs on platforms such as Coursera, EdX, etc.? Is it very uncommon for mathematicians to learn this way? As an example, suppose that an algebraic topologist wanted to get into machine learning (e.g. topological data analysis) but knew nothing about statistics/data science. Would he learn in a top-down manner and just read papers relevant to the problem he wanted to solve. Or would he actually take courses in the fundamentals of these fields (via MOOCs, textbooks, etc.)?

I know many mathematicians have blogs and post expository articles for the benefit of themselves and the readers. Or in the case of machine learning/data science there is a site called Distill. But is this better than actually taking courses in the relevant subjects?

I suppose my main question is

Do professional mathematicians learn new fields (assume they are quantitative fields) differently compared to when they were, for example, an undergraduate? Is it a waste of time for them to learn new fields from a bottom-up approach (through mediums like Coursera, EdX, textbooks, etc.) compared to a top-down approach (e.g. reading papers on arXiv).