Print all the duplicates in the string - [Updated]

PHOTO EMBED

Fri Apr 07 2023 00:11:06 GMT+0000 (Coordinated Universal Time)

Saved by @afridi #java

import java.util.*;

class Solution {
    public static void main(String[] args) {
        String str = "sinstriiintng";

        int[] counts = new int[26];

        for (int i = 0; i < str.length(); i++)
            counts[str.charAt(i) - 'a']++;

        for (int i = 0; i < 26; i++)
            if (counts[i] > 1)
                System.out.println((char)(i + 'a') + " - " + counts[i]);
    }
}
content_copyCOPY

https://takeuforward.org/data-structure/print-all-the-duplicates-in-the-string/